@linkdlab/funcnodes_react_flow 0.3.5 → 0.3.6

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.
@@ -2816,7 +2816,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
2816
2816
  \******************************************/
2817
2817
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2818
2818
 
2819
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! uuid */ \"../node_modules/uuid/dist/esm-browser/v4.js\");\n/* harmony import */ var zustand__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! zustand */ \"../node_modules/zustand/esm/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _utils_debugger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/debugger */ \"./src/utils/debugger.ts\");\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\n\n\n\n\nvar FuncNodesWorker = /** @class */ (function () {\n function FuncNodesWorker(data) {\n var _this = this;\n this.uuid = data.uuid;\n this.on_error =\n data.on_error ||\n (function (err) {\n var _a;\n (_a = _this._zustand) === null || _a === void 0 ? void 0 : _a.logger.error(err);\n });\n this.messagePromises = new Map();\n this._local_nodeupdates = new Map();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 1000);\n this.state = (0,zustand__WEBPACK_IMPORTED_MODULE_2__.create)(function (_set, _get) { return ({\n is_open: true,\n }); });\n if (data.zustand)\n this.set_zustand(data.zustand);\n if (data.on_sync_complete) {\n this.on_sync_complete = data.on_sync_complete;\n }\n else {\n this.on_sync_complete = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); }); };\n }\n }\n FuncNodesWorker.prototype.set_zustand = function (zustand) {\n if (zustand === this._zustand)\n return;\n this._zustand = zustand;\n zustand.set_worker(this);\n this._zustand.auto_progress();\n this.stepwise_fullsync();\n };\n Object.defineProperty(FuncNodesWorker.prototype, \"is_open\", {\n get: function () {\n return this.state.getState().is_open;\n },\n set: function (v) {\n this.state.setState({ is_open: v });\n },\n enumerable: false,\n configurable: true\n });\n FuncNodesWorker.prototype.stepwise_fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this.sync_lib()];\n case 1:\n _a.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 2:\n _a.sent();\n return [4 /*yield*/, this.sync_funcnodes_plugins()];\n case 3:\n _a.sent();\n return [4 /*yield*/, this.sync_nodespace()];\n case 4:\n _a.sent();\n return [4 /*yield*/, this.sync_view_state()];\n case 5:\n _a.sent();\n return [4 /*yield*/, this.on_sync_complete(this)];\n case 6:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_lib = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_library\",\n wait_for_response: true,\n retries: 2,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n lib: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_external_worker = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_worker_dependencies\",\n wait_for_response: true,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n external_worker: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_funcnodes_plugins = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_1, key, plugin, _a, _b, js, scripttag, _c, _d, css, styletag, binaryString, binaryLen, bytes, i, blob, blobUrl, module;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin_keys\",\n wait_for_response: true,\n kwargs: { type: \"react\" },\n })];\n case 1:\n resp = (_e.sent());\n _i = 0, resp_1 = resp;\n _e.label = 2;\n case 2:\n if (!(_i < resp_1.length)) return [3 /*break*/, 6];\n key = resp_1[_i];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin\",\n wait_for_response: true,\n kwargs: { key: key, type: \"react\" },\n })];\n case 3:\n plugin = _e.sent();\n if (plugin.js) {\n for (_a = 0, _b = plugin.js; _a < _b.length; _a++) {\n js = _b[_a];\n scripttag = document.createElement(\"script\");\n scripttag.text = atob(js);\n document.body.appendChild(scripttag);\n }\n }\n if (plugin.css) {\n for (_c = 0, _d = plugin.css; _c < _d.length; _c++) {\n css = _d[_c];\n styletag = document.createElement(\"style\");\n styletag.innerHTML = atob(css);\n document.head.appendChild(styletag);\n }\n }\n if (!(plugin.module !== undefined)) return [3 /*break*/, 5];\n binaryString = atob(plugin.module);\n binaryLen = binaryString.length;\n bytes = new Uint8Array(binaryLen);\n for (i = 0; i < binaryLen; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n blob = new Blob([bytes], { type: \"application/javascript\" });\n blobUrl = URL.createObjectURL(blob);\n return [4 /*yield*/, import(/* webpackIgnore: true */ blobUrl)];\n case 4:\n module = _e.sent();\n // gc the blob\n URL.revokeObjectURL(blobUrl);\n this._zustand.add_plugin(key, module.default);\n _e.label = 5;\n case 5:\n _i++;\n return [3 /*break*/, 2];\n case 6: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_view_state = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, nodeview, nodeid, nodev;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"view_state\",\n wait_for_response: true,\n })];\n case 1:\n resp = (_a.sent());\n if (resp.renderoptions)\n this._zustand.update_render_options(resp.renderoptions);\n nodeview = resp.nodes;\n if (nodeview) {\n for (nodeid in nodeview) {\n nodev = nodeview[nodeid];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n frontend: nodev,\n },\n id: nodeid,\n from_remote: true,\n });\n }\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_nodespace = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_2, node, edges, _a, edges_1, edge;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_nodes\",\n kwargs: { with_frontend: true },\n wait_for_response: true,\n })];\n case 1:\n resp = (_b.sent());\n for (_i = 0, resp_2 = resp; _i < resp_2.length; _i++) {\n node = resp_2[_i];\n this._recieve_node_added(node);\n }\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_edges\",\n wait_for_response: true,\n })];\n case 2:\n edges = (_b.sent());\n for (_a = 0, edges_1 = edges; _a < edges_1.length; _a++) {\n edge = edges_1[_a];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, e_1, nodeview, _i, _a, node, _b, _c, edge;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n _d.label = 1;\n case 1:\n if (false) {}\n _d.label = 2;\n case 2:\n _d.trys.push([2, 4, , 5]);\n return [4 /*yield*/, this._send_cmd({ cmd: \"full_state\" })];\n case 3:\n resp = (_d.sent());\n return [3 /*break*/, 6];\n case 4:\n e_1 = _d.sent();\n this._zustand.logger.error(\"Error in fullsync\", e_1);\n return [3 /*break*/, 5];\n case 5: return [3 /*break*/, 1];\n case 6:\n this._zustand.logger.debug(\"Full state\", resp);\n this._zustand.lib.libstate.getState().set({\n lib: resp.backend.lib,\n external_worker: resp.worker_dependencies,\n });\n if (resp.view.renderoptions)\n this._zustand.update_render_options(resp.view.renderoptions);\n nodeview = resp.view.nodes;\n for (_i = 0, _a = resp.backend.nodes; _i < _a.length; _i++) {\n node = _a[_i];\n if (nodeview[node.id] !== undefined) {\n node.frontend = nodeview[node.id];\n }\n this._recieve_node_added(node);\n }\n for (_b = 0, _c = resp.backend.edges; _b < _c.length; _b++) {\n edge = _c[_b];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_edge_added = function (src_nid, src_ioid, trg_nid, trg_ioid) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_edge_action(__assign({ type: \"add\", from_remote: true }, { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid }));\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.trigger_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"trigger_node\",\n kwargs: { nid: node_id },\n wait_for_response: false,\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.add_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n resp = _a.sent();\n this._recieve_node_added(resp);\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_node_added = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"add\",\n node: data,\n id: data.id,\n from_remote: true,\n });\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid, _b = _a.replace, replace = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"add_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid, replace: replace },\n });\n };\n FuncNodesWorker.prototype.remove_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid;\n return this._send_cmd({\n cmd: \"remove_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid },\n });\n };\n FuncNodesWorker.prototype.add_external_worker = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var module = _b.module, cls_module = _b.cls_module, cls_name = _b.cls_name;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_external_worker\",\n kwargs: { module: module, cls_module: cls_module, cls_name: cls_name },\n })];\n case 1: return [2 /*return*/, _c.sent()];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_local_node_updates = function () {\n var _this = this;\n clearTimeout(this._nodeupdatetimer);\n this._local_nodeupdates.forEach(function (node, id) { return __awaiter(_this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_node\",\n kwargs: { nid: id, data: node },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n }); });\n this._local_nodeupdates.clear();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 200);\n };\n FuncNodesWorker.prototype.locally_update_node = function (action) {\n // Add the type to the parameter\n var currentstate = this._local_nodeupdates.get(action.id);\n if (currentstate) {\n var _a = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.deep_merge)(currentstate, action.node), new_obj = _a.new_obj, change = _a.change;\n if (change) {\n this._local_nodeupdates.set(action.id, new_obj);\n }\n }\n else {\n this._local_nodeupdates.set(action.id, action.node);\n }\n if (action.immediate) {\n this.sync_local_node_updates();\n }\n };\n FuncNodesWorker.prototype.get_remote_node_state = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: ans.id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.set_io_value = function (_a) {\n var nid = _a.nid, ioid = _a.ioid, value = _a.value, _b = _a.set_default, set_default = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"set_io_value\",\n kwargs: { nid: nid, ioid: ioid, value: value, set_default: set_default },\n wait_for_response: true,\n });\n };\n FuncNodesWorker.prototype.clear = function () {\n return this._send_cmd({ cmd: \"clear\" });\n };\n FuncNodesWorker.prototype.save = function () {\n return this._send_cmd({ cmd: \"save\", wait_for_response: true });\n };\n FuncNodesWorker.prototype.load = function (data) {\n var _this = this;\n return this._send_cmd({\n cmd: \"load_data\",\n kwargs: { data: data },\n wait_for_response: true,\n }).then(function () {\n _this.stepwise_fullsync();\n });\n };\n FuncNodesWorker.prototype.get_io_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n value: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_ios_values = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res, mappedres, ioid;\n var nid = _b.nid;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_ios_values\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _c.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n mappedres = {};\n for (ioid in res) {\n mappedres[ioid] = { value: res[ioid] };\n }\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: mappedres,\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype._send_cmd = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var msg, wait_for_response_callback;\n var _this = this;\n var cmd = _b.cmd, kwargs = _b.kwargs, _c = _b.wait_for_response, wait_for_response = _c === void 0 ? true : _c, _d = _b.response_timeout, response_timeout = _d === void 0 ? 5000 : _d, _e = _b.retries, retries = _e === void 0 ? 2 : _e;\n return __generator(this, function (_f) {\n msg = {\n type: \"cmd\",\n cmd: cmd,\n kwargs: kwargs || {},\n };\n if (wait_for_response) {\n if (retries < 0)\n retries = 0;\n wait_for_response_callback = function () { return __awaiter(_this, void 0, void 0, function () {\n var response, _loop_1, this_1, state_1;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _loop_1 = function () {\n var msid, promise, e_2;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n msid = msg.id || (0,uuid__WEBPACK_IMPORTED_MODULE_3__[\"default\"])();\n msg.id = msid;\n promise = new Promise(function (resolve, reject) {\n var timeout = setTimeout(function () {\n reject(\"Timeout@wait_for_response for \" + cmd);\n }, response_timeout);\n _this.messagePromises.set(msid, {\n resolve: function (data) {\n clearTimeout(timeout);\n resolve(data);\n _this.messagePromises.delete(msid);\n },\n reject: function (err) {\n clearTimeout(timeout);\n reject(err);\n _this.messagePromises.delete(msid);\n },\n });\n });\n return [4 /*yield*/, this_1.send(msg)];\n case 1:\n _b.sent();\n _b.label = 2;\n case 2:\n _b.trys.push([2, 4, , 5]);\n return [4 /*yield*/, promise];\n case 3:\n response = _b.sent();\n return [2 /*return*/, \"break\"];\n case 4:\n e_2 = _b.sent();\n if (retries === 0)\n throw e_2;\n retries -= 1;\n return [2 /*return*/, \"continue\"];\n case 5: return [2 /*return*/];\n }\n });\n };\n this_1 = this;\n _a.label = 1;\n case 1:\n if (!(retries >= 0)) return [3 /*break*/, 3];\n return [5 /*yield**/, _loop_1()];\n case 2:\n state_1 = _a.sent();\n if (state_1 === \"break\")\n return [3 /*break*/, 3];\n return [3 /*break*/, 1];\n case 3: return [2 /*return*/, response];\n }\n });\n }); };\n return [2 /*return*/, wait_for_response_callback()];\n }\n return [2 /*return*/, this.send(msg)];\n });\n });\n };\n FuncNodesWorker.prototype.send = function (_data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n // this is the abstract method that should be implemented by subclasses\n throw new Error(\"Not implemented\");\n });\n });\n };\n FuncNodesWorker.prototype.handle_large_message_hint = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n return __generator(this, function (_c) {\n throw new Error(\"handle_large_message_hint not implemented \");\n });\n });\n };\n FuncNodesWorker.prototype.recieve_workerevent = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n _c = event;\n switch (_c) {\n case \"worker_error\": return [3 /*break*/, 1];\n case \"update_worker_dependencies\": return [3 /*break*/, 2];\n case \"lib_update\": return [3 /*break*/, 3];\n case \"fullsync\": return [3 /*break*/, 5];\n case \"external_worker_update\": return [3 /*break*/, 7];\n }\n return [3 /*break*/, 10];\n case 1:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.logger.error(data.error)];\n case 2:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n external_worker: data.worker_dependencies,\n })];\n case 3: return [4 /*yield*/, this.sync_lib()];\n case 4:\n _d.sent();\n return [2 /*return*/];\n case 5: return [4 /*yield*/, this.stepwise_fullsync()];\n case 6:\n _d.sent();\n return [2 /*return*/];\n case 7: return [4 /*yield*/, this.sync_lib()];\n case 8:\n _d.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 9:\n _d.sent();\n return [2 /*return*/];\n case 10:\n console.warn(\"Unhandled worker event\", event, data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve_nodespace_event = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c, _d;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_e) {\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object_size)(data, \"Data size for event \" + event, this._zustand);\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object)(data, this._zustand);\n switch (event) {\n case \"after_set_value\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_c = {},\n _c[data.io] = {\n value: data.result,\n },\n _c),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"after_update_value_options\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_d = {},\n _d[data.io] = {\n value_options: data.result,\n },\n _d),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerstart\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: true,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerdone\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: false,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"node_trigger_error\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"error\",\n errortype: \"trigger\",\n error: data.error,\n id: data.node,\n from_remote: true,\n })];\n case \"node_removed\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"delete\",\n id: data.node,\n from_remote: true,\n })];\n case \"node_added\":\n return [2 /*return*/, this._recieve_node_added(data.node)];\n case \"after_disconnect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_unforward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_connect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_forward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_add_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"after_remove_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"progress\":\n if (!this._zustand)\n return [2 /*return*/];\n if (data.node) {\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n progress: data.info,\n },\n id: data.node,\n from_remote: true,\n })];\n }\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n default:\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n }\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var promise, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n _a = data.type;\n switch (_a) {\n case \"nsevent\": return [3 /*break*/, 1];\n case \"result\": return [3 /*break*/, 3];\n case \"error\": return [3 /*break*/, 4];\n case \"progress\": return [3 /*break*/, 5];\n case \"workerevent\": return [3 /*break*/, 6];\n case \"large_message\": return [3 /*break*/, 8];\n }\n return [3 /*break*/, 10];\n case 1: return [4 /*yield*/, this.recieve_nodespace_event(data)];\n case 2: return [2 /*return*/, _b.sent()];\n case 3:\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.resolve(data.result)];\n }\n return [3 /*break*/, 11];\n case 4:\n this.on_error(data.tb + \"\\n\" + data.error);\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.reject(data.error)];\n }\n return [3 /*break*/, 11];\n case 5:\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.set_progress(data);\n return [3 /*break*/, 11];\n case 6: return [4 /*yield*/, this.recieve_workerevent(data)];\n case 7: return [2 /*return*/, _b.sent()];\n case 8: return [4 /*yield*/, this.handle_large_message_hint(data)];\n case 9: return [2 /*return*/, _b.sent()];\n case 10:\n console.warn(\"Unhandled message\", data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.disconnect = function () { };\n FuncNodesWorker.prototype.onclose = function () {\n this.is_open = false;\n if (!this._zustand)\n return;\n this._zustand.auto_progress();\n };\n FuncNodesWorker.prototype.reconnect = function () {\n return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); });\n };\n FuncNodesWorker.prototype.stop = function () {\n return __awaiter(this, void 0, void 0, function () {\n var oldonclose;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({ cmd: \"stop_worker\", wait_for_response: false })];\n case 1:\n _a.sent();\n oldonclose = this.onclose.bind(this);\n this.onclose = function () {\n oldonclose();\n if (!_this._zustand)\n return;\n if (_this._zustand.worker === _this) {\n _this._zustand.clear_all();\n }\n _this.onclose = oldonclose;\n };\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_io_full_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_full_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n fullvalue: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_io_options = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid, options = _b.options;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_io_options\",\n kwargs: __assign({ nid: nid, ioid: ioid }, options),\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = __assign({}, options),\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_node_status = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_available_modules = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_available_modules\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_external_worker = function (worker_id, class_id, data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_external_worker\",\n kwargs: __assign({ worker_id: worker_id, class_id: class_id }, data),\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_external_worker = function (worker_id, class_id) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_external_worker\",\n kwargs: { worker_id: worker_id, class_id: class_id },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.export = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"export_worker\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_from_export = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_from_export\",\n kwargs: { data: data },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n this.stepwise_fullsync();\n return [2 /*return*/, res];\n }\n });\n });\n };\n return FuncNodesWorker;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (FuncNodesWorker);\n\n\n//# sourceURL=webpack://@linkdlab/funcnodes_react_flow/./src/funcnodes/funcnodesworker.ts?");
2819
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! uuid */ \"../node_modules/uuid/dist/esm-browser/v4.js\");\n/* harmony import */ var zustand__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! zustand */ \"../node_modules/zustand/esm/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _utils_debugger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/debugger */ \"./src/utils/debugger.ts\");\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\n\n\n\n\nvar FuncNodesWorker = /** @class */ (function () {\n function FuncNodesWorker(data) {\n var _this = this;\n this.uuid = data.uuid;\n this.on_error =\n data.on_error ||\n (function (err) {\n var _a;\n (_a = _this._zustand) === null || _a === void 0 ? void 0 : _a.logger.error(err);\n });\n this.messagePromises = new Map();\n this._local_nodeupdates = new Map();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 1000);\n this.state = (0,zustand__WEBPACK_IMPORTED_MODULE_2__.create)(function (_set, _get) { return ({\n is_open: true,\n }); });\n if (data.zustand)\n this.set_zustand(data.zustand);\n if (data.on_sync_complete) {\n this.on_sync_complete = data.on_sync_complete;\n }\n else {\n this.on_sync_complete = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); }); };\n }\n }\n FuncNodesWorker.prototype.set_zustand = function (zustand) {\n if (zustand === this._zustand)\n return;\n this._zustand = zustand;\n zustand.set_worker(this);\n this._zustand.auto_progress();\n this.stepwise_fullsync();\n };\n Object.defineProperty(FuncNodesWorker.prototype, \"is_open\", {\n get: function () {\n return this.state.getState().is_open;\n },\n set: function (v) {\n this.state.setState({ is_open: v });\n },\n enumerable: false,\n configurable: true\n });\n FuncNodesWorker.prototype.stepwise_fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this.sync_lib()];\n case 1:\n _a.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 2:\n _a.sent();\n return [4 /*yield*/, this.sync_funcnodes_plugins()];\n case 3:\n _a.sent();\n return [4 /*yield*/, this.sync_nodespace()];\n case 4:\n _a.sent();\n return [4 /*yield*/, this.sync_view_state()];\n case 5:\n _a.sent();\n return [4 /*yield*/, this.on_sync_complete(this)];\n case 6:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_lib = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_library\",\n wait_for_response: true,\n retries: 2,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n lib: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_external_worker = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_worker_dependencies\",\n wait_for_response: true,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n external_worker: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_funcnodes_plugins = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_1, key, plugin, _a, _b, js, scripttag, _c, _d, css, styletag, binaryString, binaryLen, bytes, i, blob, blobUrl, module;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin_keys\",\n wait_for_response: true,\n kwargs: { type: \"react\" },\n })];\n case 1:\n resp = (_e.sent());\n _i = 0, resp_1 = resp;\n _e.label = 2;\n case 2:\n if (!(_i < resp_1.length)) return [3 /*break*/, 6];\n key = resp_1[_i];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin\",\n wait_for_response: true,\n kwargs: { key: key, type: \"react\" },\n })];\n case 3:\n plugin = _e.sent();\n if (plugin.js) {\n for (_a = 0, _b = plugin.js; _a < _b.length; _a++) {\n js = _b[_a];\n scripttag = document.createElement(\"script\");\n scripttag.text = atob(js);\n document.body.appendChild(scripttag);\n }\n }\n if (plugin.css) {\n for (_c = 0, _d = plugin.css; _c < _d.length; _c++) {\n css = _d[_c];\n styletag = document.createElement(\"style\");\n styletag.innerHTML = atob(css);\n document.head.appendChild(styletag);\n }\n }\n if (!(plugin.module !== undefined)) return [3 /*break*/, 5];\n binaryString = atob(plugin.module);\n binaryLen = binaryString.length;\n bytes = new Uint8Array(binaryLen);\n for (i = 0; i < binaryLen; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n blob = new Blob([bytes], { type: \"application/javascript\" });\n blobUrl = URL.createObjectURL(blob);\n return [4 /*yield*/, import(/* webpackIgnore: true */ blobUrl)];\n case 4:\n module = _e.sent();\n // gc the blob\n URL.revokeObjectURL(blobUrl);\n this._zustand.add_plugin(key, module.default);\n _e.label = 5;\n case 5:\n _i++;\n return [3 /*break*/, 2];\n case 6: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_view_state = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, nodeview, nodeid, nodev;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"view_state\",\n wait_for_response: true,\n })];\n case 1:\n resp = (_a.sent());\n if (resp.renderoptions)\n this._zustand.update_render_options(resp.renderoptions);\n nodeview = resp.nodes;\n if (nodeview) {\n for (nodeid in nodeview) {\n nodev = nodeview[nodeid];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n frontend: nodev,\n },\n id: nodeid,\n from_remote: true,\n });\n }\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_nodespace = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_2, node, edges, _a, edges_1, edge;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_nodes\",\n kwargs: { with_frontend: true },\n wait_for_response: true,\n })];\n case 1:\n resp = (_b.sent());\n for (_i = 0, resp_2 = resp; _i < resp_2.length; _i++) {\n node = resp_2[_i];\n this._recieve_node_added(node);\n }\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_edges\",\n wait_for_response: true,\n })];\n case 2:\n edges = (_b.sent());\n for (_a = 0, edges_1 = edges; _a < edges_1.length; _a++) {\n edge = edges_1[_a];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, e_1, nodeview, _i, _a, node, _b, _c, edge;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n _d.label = 1;\n case 1:\n if (false) {}\n _d.label = 2;\n case 2:\n _d.trys.push([2, 4, , 5]);\n return [4 /*yield*/, this._send_cmd({ cmd: \"full_state\" })];\n case 3:\n resp = (_d.sent());\n return [3 /*break*/, 6];\n case 4:\n e_1 = _d.sent();\n this._zustand.logger.error(\"Error in fullsync\", e_1);\n return [3 /*break*/, 5];\n case 5: return [3 /*break*/, 1];\n case 6:\n this._zustand.logger.debug(\"Full state\", resp);\n this._zustand.lib.libstate.getState().set({\n lib: resp.backend.lib,\n external_worker: resp.worker_dependencies,\n });\n if (resp.view.renderoptions)\n this._zustand.update_render_options(resp.view.renderoptions);\n nodeview = resp.view.nodes;\n for (_i = 0, _a = resp.backend.nodes; _i < _a.length; _i++) {\n node = _a[_i];\n if (nodeview[node.id] !== undefined) {\n node.frontend = nodeview[node.id];\n }\n this._recieve_node_added(node);\n }\n for (_b = 0, _c = resp.backend.edges; _b < _c.length; _b++) {\n edge = _c[_b];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_edge_added = function (src_nid, src_ioid, trg_nid, trg_ioid) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_edge_action(__assign({ type: \"add\", from_remote: true }, { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid }));\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.trigger_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"trigger_node\",\n kwargs: { nid: node_id },\n wait_for_response: false,\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.add_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n resp = _a.sent();\n this._recieve_node_added(resp);\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_node_added = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"add\",\n node: data,\n id: data.id,\n from_remote: true,\n });\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid, _b = _a.replace, replace = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"add_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid, replace: replace },\n });\n };\n FuncNodesWorker.prototype.remove_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid;\n return this._send_cmd({\n cmd: \"remove_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid },\n });\n };\n FuncNodesWorker.prototype.add_external_worker = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var module = _b.module, cls_module = _b.cls_module, cls_name = _b.cls_name;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_external_worker\",\n kwargs: { module: module, cls_module: cls_module, cls_name: cls_name },\n })];\n case 1: return [2 /*return*/, _c.sent()];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_local_node_updates = function () {\n var _this = this;\n clearTimeout(this._nodeupdatetimer);\n this._local_nodeupdates.forEach(function (node, id) { return __awaiter(_this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_node\",\n kwargs: { nid: id, data: node },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n }); });\n this._local_nodeupdates.clear();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 200);\n };\n FuncNodesWorker.prototype.locally_update_node = function (action) {\n // Add the type to the parameter\n var currentstate = this._local_nodeupdates.get(action.id);\n if (currentstate) {\n var _a = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.deep_merge)(currentstate, action.node), new_obj = _a.new_obj, change = _a.change;\n if (change) {\n this._local_nodeupdates.set(action.id, new_obj);\n }\n }\n else {\n this._local_nodeupdates.set(action.id, action.node);\n }\n if (action.immediate) {\n this.sync_local_node_updates();\n }\n };\n FuncNodesWorker.prototype.get_remote_node_state = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: ans.id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.set_io_value = function (_a) {\n var nid = _a.nid, ioid = _a.ioid, value = _a.value, _b = _a.set_default, set_default = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"set_io_value\",\n kwargs: { nid: nid, ioid: ioid, value: value, set_default: set_default },\n wait_for_response: true,\n });\n };\n FuncNodesWorker.prototype.clear = function () {\n return this._send_cmd({ cmd: \"clear\" });\n };\n FuncNodesWorker.prototype.save = function () {\n return this._send_cmd({ cmd: \"save\", wait_for_response: true });\n };\n FuncNodesWorker.prototype.load = function (data) {\n var _this = this;\n return this._send_cmd({\n cmd: \"load_data\",\n kwargs: { data: data },\n wait_for_response: true,\n }).then(function () {\n _this.stepwise_fullsync();\n });\n };\n FuncNodesWorker.prototype.get_io_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n value: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_ios_values = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res, mappedres, ioid;\n var nid = _b.nid;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_ios_values\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _c.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n mappedres = {};\n for (ioid in res) {\n mappedres[ioid] = { value: res[ioid] };\n }\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: mappedres,\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype._send_cmd = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var msg, wait_for_response_callback;\n var _this = this;\n var cmd = _b.cmd, kwargs = _b.kwargs, _c = _b.wait_for_response, wait_for_response = _c === void 0 ? true : _c, _d = _b.response_timeout, response_timeout = _d === void 0 ? 5000 : _d, _e = _b.retries, retries = _e === void 0 ? 2 : _e;\n return __generator(this, function (_f) {\n msg = {\n type: \"cmd\",\n cmd: cmd,\n kwargs: kwargs || {},\n };\n if (wait_for_response) {\n if (retries < 0)\n retries = 0;\n wait_for_response_callback = function () { return __awaiter(_this, void 0, void 0, function () {\n var response, _loop_1, this_1, state_1;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _loop_1 = function () {\n var msid, promise, e_2;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n msid = msg.id || (0,uuid__WEBPACK_IMPORTED_MODULE_3__[\"default\"])();\n msg.id = msid;\n promise = new Promise(function (resolve, reject) {\n var timeout = setTimeout(function () {\n reject(\"Timeout@wait_for_response for \" + cmd);\n }, response_timeout);\n _this.messagePromises.set(msid, {\n resolve: function (data) {\n clearTimeout(timeout);\n resolve(data);\n _this.messagePromises.delete(msid);\n },\n reject: function (err) {\n clearTimeout(timeout);\n reject(err);\n _this.messagePromises.delete(msid);\n },\n });\n });\n return [4 /*yield*/, this_1.send(msg)];\n case 1:\n _b.sent();\n _b.label = 2;\n case 2:\n _b.trys.push([2, 4, , 5]);\n return [4 /*yield*/, promise];\n case 3:\n response = _b.sent();\n return [2 /*return*/, \"break\"];\n case 4:\n e_2 = _b.sent();\n if (retries === 0)\n throw e_2;\n retries -= 1;\n return [2 /*return*/, \"continue\"];\n case 5: return [2 /*return*/];\n }\n });\n };\n this_1 = this;\n _a.label = 1;\n case 1:\n if (!(retries >= 0)) return [3 /*break*/, 3];\n return [5 /*yield**/, _loop_1()];\n case 2:\n state_1 = _a.sent();\n if (state_1 === \"break\")\n return [3 /*break*/, 3];\n return [3 /*break*/, 1];\n case 3: return [2 /*return*/, response];\n }\n });\n }); };\n return [2 /*return*/, wait_for_response_callback()];\n }\n return [2 /*return*/, this.send(msg)];\n });\n });\n };\n FuncNodesWorker.prototype.send = function (_data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n // this is the abstract method that should be implemented by subclasses\n throw new Error(\"Not implemented\");\n });\n });\n };\n FuncNodesWorker.prototype.upload_file = function (_files, _onProgressCallback) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n throw new Error(\"handle_large_message_hint not implemented \");\n });\n });\n };\n FuncNodesWorker.prototype.handle_large_message_hint = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n return __generator(this, function (_c) {\n throw new Error(\"handle_large_message_hint not implemented \");\n });\n });\n };\n FuncNodesWorker.prototype.recieve_workerevent = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n _c = event;\n switch (_c) {\n case \"worker_error\": return [3 /*break*/, 1];\n case \"update_worker_dependencies\": return [3 /*break*/, 2];\n case \"lib_update\": return [3 /*break*/, 3];\n case \"fullsync\": return [3 /*break*/, 5];\n case \"external_worker_update\": return [3 /*break*/, 7];\n }\n return [3 /*break*/, 10];\n case 1:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.logger.error(data.error)];\n case 2:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n external_worker: data.worker_dependencies,\n })];\n case 3: return [4 /*yield*/, this.sync_lib()];\n case 4:\n _d.sent();\n return [2 /*return*/];\n case 5: return [4 /*yield*/, this.stepwise_fullsync()];\n case 6:\n _d.sent();\n return [2 /*return*/];\n case 7: return [4 /*yield*/, this.sync_lib()];\n case 8:\n _d.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 9:\n _d.sent();\n return [2 /*return*/];\n case 10:\n console.warn(\"Unhandled worker event\", event, data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve_nodespace_event = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c, _d;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_e) {\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object_size)(data, \"Data size for event \" + event, this._zustand);\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object)(data, this._zustand);\n switch (event) {\n case \"after_set_value\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_c = {},\n _c[data.io] = {\n value: data.result,\n },\n _c),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"after_update_value_options\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_d = {},\n _d[data.io] = {\n value_options: data.result,\n },\n _d),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerstart\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: true,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerdone\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: false,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"node_trigger_error\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"error\",\n errortype: \"trigger\",\n error: data.error,\n id: data.node,\n from_remote: true,\n })];\n case \"node_removed\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"delete\",\n id: data.node,\n from_remote: true,\n })];\n case \"node_added\":\n return [2 /*return*/, this._recieve_node_added(data.node)];\n case \"after_disconnect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_unforward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_connect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_forward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_add_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"after_remove_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"progress\":\n if (!this._zustand)\n return [2 /*return*/];\n if (data.node) {\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n progress: data.info,\n },\n id: data.node,\n from_remote: true,\n })];\n }\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n default:\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n }\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var promise, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n _a = data.type;\n switch (_a) {\n case \"nsevent\": return [3 /*break*/, 1];\n case \"result\": return [3 /*break*/, 3];\n case \"error\": return [3 /*break*/, 4];\n case \"progress\": return [3 /*break*/, 5];\n case \"workerevent\": return [3 /*break*/, 6];\n case \"large_message\": return [3 /*break*/, 8];\n }\n return [3 /*break*/, 10];\n case 1: return [4 /*yield*/, this.recieve_nodespace_event(data)];\n case 2: return [2 /*return*/, _b.sent()];\n case 3:\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.resolve(data.result)];\n }\n return [3 /*break*/, 11];\n case 4:\n this.on_error(data.tb + \"\\n\" + data.error);\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.reject(data.error)];\n }\n return [3 /*break*/, 11];\n case 5:\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.set_progress(data);\n return [3 /*break*/, 11];\n case 6: return [4 /*yield*/, this.recieve_workerevent(data)];\n case 7: return [2 /*return*/, _b.sent()];\n case 8: return [4 /*yield*/, this.handle_large_message_hint(data)];\n case 9: return [2 /*return*/, _b.sent()];\n case 10:\n console.warn(\"Unhandled message\", data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.disconnect = function () { };\n FuncNodesWorker.prototype.onclose = function () {\n this.is_open = false;\n if (!this._zustand)\n return;\n this._zustand.auto_progress();\n };\n FuncNodesWorker.prototype.reconnect = function () {\n return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); });\n };\n FuncNodesWorker.prototype.stop = function () {\n return __awaiter(this, void 0, void 0, function () {\n var oldonclose;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({ cmd: \"stop_worker\", wait_for_response: false })];\n case 1:\n _a.sent();\n oldonclose = this.onclose.bind(this);\n this.onclose = function () {\n oldonclose();\n if (!_this._zustand)\n return;\n if (_this._zustand.worker === _this) {\n _this._zustand.clear_all();\n }\n _this.onclose = oldonclose;\n };\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_io_full_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_full_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n fullvalue: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_io_options = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid, options = _b.options;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_io_options\",\n kwargs: __assign({ nid: nid, ioid: ioid }, options),\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = __assign({}, options),\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_node_status = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_available_modules = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_available_modules\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_external_worker = function (worker_id, class_id, data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_external_worker\",\n kwargs: __assign({ worker_id: worker_id, class_id: class_id }, data),\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_external_worker = function (worker_id, class_id) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_external_worker\",\n kwargs: { worker_id: worker_id, class_id: class_id },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.export = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"export_worker\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_from_export = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_from_export\",\n kwargs: { data: data },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n this.stepwise_fullsync();\n return [2 /*return*/, res];\n }\n });\n });\n };\n return FuncNodesWorker;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (FuncNodesWorker);\n\n\n//# sourceURL=webpack://@linkdlab/funcnodes_react_flow/./src/funcnodes/funcnodesworker.ts?");
2820
2820
 
2821
2821
  /***/ }),
2822
2822
 
@@ -83,6 +83,7 @@ declare class FuncNodesWorker {
83
83
  retries?: number;
84
84
  }): Promise<any>;
85
85
  send(_data: any): Promise<void>;
86
+ upload_file(_files: File[] | FileList, _onProgressCallback?: (loaded: number, total?: number) => void): Promise<void>;
86
87
  handle_large_message_hint({}: LargeMessageHint): Promise<void>;
87
88
  recieve_workerevent({ event, data }: WorkerEvent): Promise<void>;
88
89
  recieve_nodespace_event({ event, data }: NodeSpaceEvent): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"funcnodesworker.d.ts","sourceRoot":"","sources":["../../../src/funcnodes/funcnodesworker.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"funcnodesworker.d.ts","sourceRoot":"","sources":["../../../src/funcnodes/funcnodesworker.ts"],"names":[],"mappings":"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"}
@@ -3163,7 +3163,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
3163
3163
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
3164
3164
 
3165
3165
  "use strict";
3166
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! uuid */ \"../node_modules/uuid/dist/esm-browser/v4.js\");\n/* harmony import */ var zustand__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! zustand */ \"../node_modules/zustand/esm/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _utils_debugger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/debugger */ \"./src/utils/debugger.ts\");\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\n\n\n\n\nvar FuncNodesWorker = /** @class */ (function () {\n function FuncNodesWorker(data) {\n var _this = this;\n this.uuid = data.uuid;\n this.on_error =\n data.on_error ||\n (function (err) {\n var _a;\n (_a = _this._zustand) === null || _a === void 0 ? void 0 : _a.logger.error(err);\n });\n this.messagePromises = new Map();\n this._local_nodeupdates = new Map();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 1000);\n this.state = (0,zustand__WEBPACK_IMPORTED_MODULE_2__.create)(function (_set, _get) { return ({\n is_open: true,\n }); });\n if (data.zustand)\n this.set_zustand(data.zustand);\n if (data.on_sync_complete) {\n this.on_sync_complete = data.on_sync_complete;\n }\n else {\n this.on_sync_complete = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); }); };\n }\n }\n FuncNodesWorker.prototype.set_zustand = function (zustand) {\n if (zustand === this._zustand)\n return;\n this._zustand = zustand;\n zustand.set_worker(this);\n this._zustand.auto_progress();\n this.stepwise_fullsync();\n };\n Object.defineProperty(FuncNodesWorker.prototype, \"is_open\", {\n get: function () {\n return this.state.getState().is_open;\n },\n set: function (v) {\n this.state.setState({ is_open: v });\n },\n enumerable: false,\n configurable: true\n });\n FuncNodesWorker.prototype.stepwise_fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this.sync_lib()];\n case 1:\n _a.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 2:\n _a.sent();\n return [4 /*yield*/, this.sync_funcnodes_plugins()];\n case 3:\n _a.sent();\n return [4 /*yield*/, this.sync_nodespace()];\n case 4:\n _a.sent();\n return [4 /*yield*/, this.sync_view_state()];\n case 5:\n _a.sent();\n return [4 /*yield*/, this.on_sync_complete(this)];\n case 6:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_lib = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_library\",\n wait_for_response: true,\n retries: 2,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n lib: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_external_worker = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_worker_dependencies\",\n wait_for_response: true,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n external_worker: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_funcnodes_plugins = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_1, key, plugin, _a, _b, js, scripttag, _c, _d, css, styletag, binaryString, binaryLen, bytes, i, blob, blobUrl, module;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin_keys\",\n wait_for_response: true,\n kwargs: { type: \"react\" },\n })];\n case 1:\n resp = (_e.sent());\n _i = 0, resp_1 = resp;\n _e.label = 2;\n case 2:\n if (!(_i < resp_1.length)) return [3 /*break*/, 6];\n key = resp_1[_i];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin\",\n wait_for_response: true,\n kwargs: { key: key, type: \"react\" },\n })];\n case 3:\n plugin = _e.sent();\n if (plugin.js) {\n for (_a = 0, _b = plugin.js; _a < _b.length; _a++) {\n js = _b[_a];\n scripttag = document.createElement(\"script\");\n scripttag.text = atob(js);\n document.body.appendChild(scripttag);\n }\n }\n if (plugin.css) {\n for (_c = 0, _d = plugin.css; _c < _d.length; _c++) {\n css = _d[_c];\n styletag = document.createElement(\"style\");\n styletag.innerHTML = atob(css);\n document.head.appendChild(styletag);\n }\n }\n if (!(plugin.module !== undefined)) return [3 /*break*/, 5];\n binaryString = atob(plugin.module);\n binaryLen = binaryString.length;\n bytes = new Uint8Array(binaryLen);\n for (i = 0; i < binaryLen; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n blob = new Blob([bytes], { type: \"application/javascript\" });\n blobUrl = URL.createObjectURL(blob);\n return [4 /*yield*/, import(/* webpackIgnore: true */ blobUrl)];\n case 4:\n module = _e.sent();\n // gc the blob\n URL.revokeObjectURL(blobUrl);\n this._zustand.add_plugin(key, module.default);\n _e.label = 5;\n case 5:\n _i++;\n return [3 /*break*/, 2];\n case 6: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_view_state = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, nodeview, nodeid, nodev;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"view_state\",\n wait_for_response: true,\n })];\n case 1:\n resp = (_a.sent());\n if (resp.renderoptions)\n this._zustand.update_render_options(resp.renderoptions);\n nodeview = resp.nodes;\n if (nodeview) {\n for (nodeid in nodeview) {\n nodev = nodeview[nodeid];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n frontend: nodev,\n },\n id: nodeid,\n from_remote: true,\n });\n }\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_nodespace = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_2, node, edges, _a, edges_1, edge;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_nodes\",\n kwargs: { with_frontend: true },\n wait_for_response: true,\n })];\n case 1:\n resp = (_b.sent());\n for (_i = 0, resp_2 = resp; _i < resp_2.length; _i++) {\n node = resp_2[_i];\n this._recieve_node_added(node);\n }\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_edges\",\n wait_for_response: true,\n })];\n case 2:\n edges = (_b.sent());\n for (_a = 0, edges_1 = edges; _a < edges_1.length; _a++) {\n edge = edges_1[_a];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, e_1, nodeview, _i, _a, node, _b, _c, edge;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n _d.label = 1;\n case 1:\n if (false) {}\n _d.label = 2;\n case 2:\n _d.trys.push([2, 4, , 5]);\n return [4 /*yield*/, this._send_cmd({ cmd: \"full_state\" })];\n case 3:\n resp = (_d.sent());\n return [3 /*break*/, 6];\n case 4:\n e_1 = _d.sent();\n this._zustand.logger.error(\"Error in fullsync\", e_1);\n return [3 /*break*/, 5];\n case 5: return [3 /*break*/, 1];\n case 6:\n this._zustand.logger.debug(\"Full state\", resp);\n this._zustand.lib.libstate.getState().set({\n lib: resp.backend.lib,\n external_worker: resp.worker_dependencies,\n });\n if (resp.view.renderoptions)\n this._zustand.update_render_options(resp.view.renderoptions);\n nodeview = resp.view.nodes;\n for (_i = 0, _a = resp.backend.nodes; _i < _a.length; _i++) {\n node = _a[_i];\n if (nodeview[node.id] !== undefined) {\n node.frontend = nodeview[node.id];\n }\n this._recieve_node_added(node);\n }\n for (_b = 0, _c = resp.backend.edges; _b < _c.length; _b++) {\n edge = _c[_b];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_edge_added = function (src_nid, src_ioid, trg_nid, trg_ioid) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_edge_action(__assign({ type: \"add\", from_remote: true }, { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid }));\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.trigger_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"trigger_node\",\n kwargs: { nid: node_id },\n wait_for_response: false,\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.add_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n resp = _a.sent();\n this._recieve_node_added(resp);\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_node_added = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"add\",\n node: data,\n id: data.id,\n from_remote: true,\n });\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid, _b = _a.replace, replace = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"add_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid, replace: replace },\n });\n };\n FuncNodesWorker.prototype.remove_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid;\n return this._send_cmd({\n cmd: \"remove_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid },\n });\n };\n FuncNodesWorker.prototype.add_external_worker = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var module = _b.module, cls_module = _b.cls_module, cls_name = _b.cls_name;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_external_worker\",\n kwargs: { module: module, cls_module: cls_module, cls_name: cls_name },\n })];\n case 1: return [2 /*return*/, _c.sent()];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_local_node_updates = function () {\n var _this = this;\n clearTimeout(this._nodeupdatetimer);\n this._local_nodeupdates.forEach(function (node, id) { return __awaiter(_this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_node\",\n kwargs: { nid: id, data: node },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n }); });\n this._local_nodeupdates.clear();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 200);\n };\n FuncNodesWorker.prototype.locally_update_node = function (action) {\n // Add the type to the parameter\n var currentstate = this._local_nodeupdates.get(action.id);\n if (currentstate) {\n var _a = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.deep_merge)(currentstate, action.node), new_obj = _a.new_obj, change = _a.change;\n if (change) {\n this._local_nodeupdates.set(action.id, new_obj);\n }\n }\n else {\n this._local_nodeupdates.set(action.id, action.node);\n }\n if (action.immediate) {\n this.sync_local_node_updates();\n }\n };\n FuncNodesWorker.prototype.get_remote_node_state = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: ans.id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.set_io_value = function (_a) {\n var nid = _a.nid, ioid = _a.ioid, value = _a.value, _b = _a.set_default, set_default = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"set_io_value\",\n kwargs: { nid: nid, ioid: ioid, value: value, set_default: set_default },\n wait_for_response: true,\n });\n };\n FuncNodesWorker.prototype.clear = function () {\n return this._send_cmd({ cmd: \"clear\" });\n };\n FuncNodesWorker.prototype.save = function () {\n return this._send_cmd({ cmd: \"save\", wait_for_response: true });\n };\n FuncNodesWorker.prototype.load = function (data) {\n var _this = this;\n return this._send_cmd({\n cmd: \"load_data\",\n kwargs: { data: data },\n wait_for_response: true,\n }).then(function () {\n _this.stepwise_fullsync();\n });\n };\n FuncNodesWorker.prototype.get_io_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n value: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_ios_values = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res, mappedres, ioid;\n var nid = _b.nid;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_ios_values\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _c.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n mappedres = {};\n for (ioid in res) {\n mappedres[ioid] = { value: res[ioid] };\n }\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: mappedres,\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype._send_cmd = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var msg, wait_for_response_callback;\n var _this = this;\n var cmd = _b.cmd, kwargs = _b.kwargs, _c = _b.wait_for_response, wait_for_response = _c === void 0 ? true : _c, _d = _b.response_timeout, response_timeout = _d === void 0 ? 5000 : _d, _e = _b.retries, retries = _e === void 0 ? 2 : _e;\n return __generator(this, function (_f) {\n msg = {\n type: \"cmd\",\n cmd: cmd,\n kwargs: kwargs || {},\n };\n if (wait_for_response) {\n if (retries < 0)\n retries = 0;\n wait_for_response_callback = function () { return __awaiter(_this, void 0, void 0, function () {\n var response, _loop_1, this_1, state_1;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _loop_1 = function () {\n var msid, promise, e_2;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n msid = msg.id || (0,uuid__WEBPACK_IMPORTED_MODULE_3__[\"default\"])();\n msg.id = msid;\n promise = new Promise(function (resolve, reject) {\n var timeout = setTimeout(function () {\n reject(\"Timeout@wait_for_response for \" + cmd);\n }, response_timeout);\n _this.messagePromises.set(msid, {\n resolve: function (data) {\n clearTimeout(timeout);\n resolve(data);\n _this.messagePromises.delete(msid);\n },\n reject: function (err) {\n clearTimeout(timeout);\n reject(err);\n _this.messagePromises.delete(msid);\n },\n });\n });\n return [4 /*yield*/, this_1.send(msg)];\n case 1:\n _b.sent();\n _b.label = 2;\n case 2:\n _b.trys.push([2, 4, , 5]);\n return [4 /*yield*/, promise];\n case 3:\n response = _b.sent();\n return [2 /*return*/, \"break\"];\n case 4:\n e_2 = _b.sent();\n if (retries === 0)\n throw e_2;\n retries -= 1;\n return [2 /*return*/, \"continue\"];\n case 5: return [2 /*return*/];\n }\n });\n };\n this_1 = this;\n _a.label = 1;\n case 1:\n if (!(retries >= 0)) return [3 /*break*/, 3];\n return [5 /*yield**/, _loop_1()];\n case 2:\n state_1 = _a.sent();\n if (state_1 === \"break\")\n return [3 /*break*/, 3];\n return [3 /*break*/, 1];\n case 3: return [2 /*return*/, response];\n }\n });\n }); };\n return [2 /*return*/, wait_for_response_callback()];\n }\n return [2 /*return*/, this.send(msg)];\n });\n });\n };\n FuncNodesWorker.prototype.send = function (_data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n // this is the abstract method that should be implemented by subclasses\n throw new Error(\"Not implemented\");\n });\n });\n };\n FuncNodesWorker.prototype.handle_large_message_hint = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n return __generator(this, function (_c) {\n throw new Error(\"handle_large_message_hint not implemented \");\n });\n });\n };\n FuncNodesWorker.prototype.recieve_workerevent = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n _c = event;\n switch (_c) {\n case \"worker_error\": return [3 /*break*/, 1];\n case \"update_worker_dependencies\": return [3 /*break*/, 2];\n case \"lib_update\": return [3 /*break*/, 3];\n case \"fullsync\": return [3 /*break*/, 5];\n case \"external_worker_update\": return [3 /*break*/, 7];\n }\n return [3 /*break*/, 10];\n case 1:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.logger.error(data.error)];\n case 2:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n external_worker: data.worker_dependencies,\n })];\n case 3: return [4 /*yield*/, this.sync_lib()];\n case 4:\n _d.sent();\n return [2 /*return*/];\n case 5: return [4 /*yield*/, this.stepwise_fullsync()];\n case 6:\n _d.sent();\n return [2 /*return*/];\n case 7: return [4 /*yield*/, this.sync_lib()];\n case 8:\n _d.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 9:\n _d.sent();\n return [2 /*return*/];\n case 10:\n console.warn(\"Unhandled worker event\", event, data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve_nodespace_event = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c, _d;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_e) {\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object_size)(data, \"Data size for event \" + event, this._zustand);\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object)(data, this._zustand);\n switch (event) {\n case \"after_set_value\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_c = {},\n _c[data.io] = {\n value: data.result,\n },\n _c),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"after_update_value_options\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_d = {},\n _d[data.io] = {\n value_options: data.result,\n },\n _d),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerstart\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: true,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerdone\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: false,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"node_trigger_error\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"error\",\n errortype: \"trigger\",\n error: data.error,\n id: data.node,\n from_remote: true,\n })];\n case \"node_removed\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"delete\",\n id: data.node,\n from_remote: true,\n })];\n case \"node_added\":\n return [2 /*return*/, this._recieve_node_added(data.node)];\n case \"after_disconnect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_unforward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_connect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_forward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_add_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"after_remove_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"progress\":\n if (!this._zustand)\n return [2 /*return*/];\n if (data.node) {\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n progress: data.info,\n },\n id: data.node,\n from_remote: true,\n })];\n }\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n default:\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n }\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var promise, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n _a = data.type;\n switch (_a) {\n case \"nsevent\": return [3 /*break*/, 1];\n case \"result\": return [3 /*break*/, 3];\n case \"error\": return [3 /*break*/, 4];\n case \"progress\": return [3 /*break*/, 5];\n case \"workerevent\": return [3 /*break*/, 6];\n case \"large_message\": return [3 /*break*/, 8];\n }\n return [3 /*break*/, 10];\n case 1: return [4 /*yield*/, this.recieve_nodespace_event(data)];\n case 2: return [2 /*return*/, _b.sent()];\n case 3:\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.resolve(data.result)];\n }\n return [3 /*break*/, 11];\n case 4:\n this.on_error(data.tb + \"\\n\" + data.error);\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.reject(data.error)];\n }\n return [3 /*break*/, 11];\n case 5:\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.set_progress(data);\n return [3 /*break*/, 11];\n case 6: return [4 /*yield*/, this.recieve_workerevent(data)];\n case 7: return [2 /*return*/, _b.sent()];\n case 8: return [4 /*yield*/, this.handle_large_message_hint(data)];\n case 9: return [2 /*return*/, _b.sent()];\n case 10:\n console.warn(\"Unhandled message\", data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.disconnect = function () { };\n FuncNodesWorker.prototype.onclose = function () {\n this.is_open = false;\n if (!this._zustand)\n return;\n this._zustand.auto_progress();\n };\n FuncNodesWorker.prototype.reconnect = function () {\n return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); });\n };\n FuncNodesWorker.prototype.stop = function () {\n return __awaiter(this, void 0, void 0, function () {\n var oldonclose;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({ cmd: \"stop_worker\", wait_for_response: false })];\n case 1:\n _a.sent();\n oldonclose = this.onclose.bind(this);\n this.onclose = function () {\n oldonclose();\n if (!_this._zustand)\n return;\n if (_this._zustand.worker === _this) {\n _this._zustand.clear_all();\n }\n _this.onclose = oldonclose;\n };\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_io_full_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_full_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n fullvalue: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_io_options = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid, options = _b.options;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_io_options\",\n kwargs: __assign({ nid: nid, ioid: ioid }, options),\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = __assign({}, options),\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_node_status = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_available_modules = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_available_modules\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_external_worker = function (worker_id, class_id, data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_external_worker\",\n kwargs: __assign({ worker_id: worker_id, class_id: class_id }, data),\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_external_worker = function (worker_id, class_id) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_external_worker\",\n kwargs: { worker_id: worker_id, class_id: class_id },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.export = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"export_worker\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_from_export = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_from_export\",\n kwargs: { data: data },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n this.stepwise_fullsync();\n return [2 /*return*/, res];\n }\n });\n });\n };\n return FuncNodesWorker;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (FuncNodesWorker);\n\n\n//# sourceURL=webpack://FuncNodesReact/./src/funcnodes/funcnodesworker.ts?");
3166
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! uuid */ \"../node_modules/uuid/dist/esm-browser/v4.js\");\n/* harmony import */ var zustand__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! zustand */ \"../node_modules/zustand/esm/index.mjs\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ \"./src/utils/index.ts\");\n/* harmony import */ var _utils_debugger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/debugger */ \"./src/utils/debugger.ts\");\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\n\n\n\n\nvar FuncNodesWorker = /** @class */ (function () {\n function FuncNodesWorker(data) {\n var _this = this;\n this.uuid = data.uuid;\n this.on_error =\n data.on_error ||\n (function (err) {\n var _a;\n (_a = _this._zustand) === null || _a === void 0 ? void 0 : _a.logger.error(err);\n });\n this.messagePromises = new Map();\n this._local_nodeupdates = new Map();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 1000);\n this.state = (0,zustand__WEBPACK_IMPORTED_MODULE_2__.create)(function (_set, _get) { return ({\n is_open: true,\n }); });\n if (data.zustand)\n this.set_zustand(data.zustand);\n if (data.on_sync_complete) {\n this.on_sync_complete = data.on_sync_complete;\n }\n else {\n this.on_sync_complete = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); }); };\n }\n }\n FuncNodesWorker.prototype.set_zustand = function (zustand) {\n if (zustand === this._zustand)\n return;\n this._zustand = zustand;\n zustand.set_worker(this);\n this._zustand.auto_progress();\n this.stepwise_fullsync();\n };\n Object.defineProperty(FuncNodesWorker.prototype, \"is_open\", {\n get: function () {\n return this.state.getState().is_open;\n },\n set: function (v) {\n this.state.setState({ is_open: v });\n },\n enumerable: false,\n configurable: true\n });\n FuncNodesWorker.prototype.stepwise_fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this.sync_lib()];\n case 1:\n _a.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 2:\n _a.sent();\n return [4 /*yield*/, this.sync_funcnodes_plugins()];\n case 3:\n _a.sent();\n return [4 /*yield*/, this.sync_nodespace()];\n case 4:\n _a.sent();\n return [4 /*yield*/, this.sync_view_state()];\n case 5:\n _a.sent();\n return [4 /*yield*/, this.on_sync_complete(this)];\n case 6:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_lib = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_library\",\n wait_for_response: true,\n retries: 2,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n lib: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_external_worker = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_worker_dependencies\",\n wait_for_response: true,\n })];\n case 1:\n resp = _a.sent();\n this._zustand.lib.libstate.getState().set({\n external_worker: resp,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_funcnodes_plugins = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_1, key, plugin, _a, _b, js, scripttag, _c, _d, css, styletag, binaryString, binaryLen, bytes, i, blob, blobUrl, module;\n return __generator(this, function (_e) {\n switch (_e.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin_keys\",\n wait_for_response: true,\n kwargs: { type: \"react\" },\n })];\n case 1:\n resp = (_e.sent());\n _i = 0, resp_1 = resp;\n _e.label = 2;\n case 2:\n if (!(_i < resp_1.length)) return [3 /*break*/, 6];\n key = resp_1[_i];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_plugin\",\n wait_for_response: true,\n kwargs: { key: key, type: \"react\" },\n })];\n case 3:\n plugin = _e.sent();\n if (plugin.js) {\n for (_a = 0, _b = plugin.js; _a < _b.length; _a++) {\n js = _b[_a];\n scripttag = document.createElement(\"script\");\n scripttag.text = atob(js);\n document.body.appendChild(scripttag);\n }\n }\n if (plugin.css) {\n for (_c = 0, _d = plugin.css; _c < _d.length; _c++) {\n css = _d[_c];\n styletag = document.createElement(\"style\");\n styletag.innerHTML = atob(css);\n document.head.appendChild(styletag);\n }\n }\n if (!(plugin.module !== undefined)) return [3 /*break*/, 5];\n binaryString = atob(plugin.module);\n binaryLen = binaryString.length;\n bytes = new Uint8Array(binaryLen);\n for (i = 0; i < binaryLen; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n blob = new Blob([bytes], { type: \"application/javascript\" });\n blobUrl = URL.createObjectURL(blob);\n return [4 /*yield*/, import(/* webpackIgnore: true */ blobUrl)];\n case 4:\n module = _e.sent();\n // gc the blob\n URL.revokeObjectURL(blobUrl);\n this._zustand.add_plugin(key, module.default);\n _e.label = 5;\n case 5:\n _i++;\n return [3 /*break*/, 2];\n case 6: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_view_state = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, nodeview, nodeid, nodev;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"view_state\",\n wait_for_response: true,\n })];\n case 1:\n resp = (_a.sent());\n if (resp.renderoptions)\n this._zustand.update_render_options(resp.renderoptions);\n nodeview = resp.nodes;\n if (nodeview) {\n for (nodeid in nodeview) {\n nodev = nodeview[nodeid];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n frontend: nodev,\n },\n id: nodeid,\n from_remote: true,\n });\n }\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_nodespace = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, _i, resp_2, node, edges, _a, edges_1, edge;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_nodes\",\n kwargs: { with_frontend: true },\n wait_for_response: true,\n })];\n case 1:\n resp = (_b.sent());\n for (_i = 0, resp_2 = resp; _i < resp_2.length; _i++) {\n node = resp_2[_i];\n this._recieve_node_added(node);\n }\n return [4 /*yield*/, this._send_cmd({\n cmd: \"get_edges\",\n wait_for_response: true,\n })];\n case 2:\n edges = (_b.sent());\n for (_a = 0, edges_1 = edges; _a < edges_1.length; _a++) {\n edge = edges_1[_a];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.fullsync = function () {\n return __awaiter(this, void 0, void 0, function () {\n var resp, e_1, nodeview, _i, _a, node, _b, _c, edge;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n if (!this._zustand)\n return [2 /*return*/];\n if (!this.is_open)\n return [2 /*return*/];\n _d.label = 1;\n case 1:\n if (false) {}\n _d.label = 2;\n case 2:\n _d.trys.push([2, 4, , 5]);\n return [4 /*yield*/, this._send_cmd({ cmd: \"full_state\" })];\n case 3:\n resp = (_d.sent());\n return [3 /*break*/, 6];\n case 4:\n e_1 = _d.sent();\n this._zustand.logger.error(\"Error in fullsync\", e_1);\n return [3 /*break*/, 5];\n case 5: return [3 /*break*/, 1];\n case 6:\n this._zustand.logger.debug(\"Full state\", resp);\n this._zustand.lib.libstate.getState().set({\n lib: resp.backend.lib,\n external_worker: resp.worker_dependencies,\n });\n if (resp.view.renderoptions)\n this._zustand.update_render_options(resp.view.renderoptions);\n nodeview = resp.view.nodes;\n for (_i = 0, _a = resp.backend.nodes; _i < _a.length; _i++) {\n node = _a[_i];\n if (nodeview[node.id] !== undefined) {\n node.frontend = nodeview[node.id];\n }\n this._recieve_node_added(node);\n }\n for (_b = 0, _c = resp.backend.edges; _b < _c.length; _b++) {\n edge = _c[_b];\n this._recieve_edge_added.apply(this, edge);\n }\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_edge_added = function (src_nid, src_ioid, trg_nid, trg_ioid) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_edge_action(__assign({ type: \"add\", from_remote: true }, { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid }));\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.trigger_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"trigger_node\",\n kwargs: { nid: node_id },\n wait_for_response: false,\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.add_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n var resp;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n resp = _a.sent();\n this._recieve_node_added(resp);\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_node = function (node_id) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_node\",\n kwargs: { id: node_id },\n })];\n case 1:\n _a.sent();\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype._recieve_node_added = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"add\",\n node: data,\n id: data.id,\n from_remote: true,\n });\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid, _b = _a.replace, replace = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"add_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid, replace: replace },\n });\n };\n FuncNodesWorker.prototype.remove_edge = function (_a) {\n var src_nid = _a.src_nid, src_ioid = _a.src_ioid, trg_nid = _a.trg_nid, trg_ioid = _a.trg_ioid;\n return this._send_cmd({\n cmd: \"remove_edge\",\n kwargs: { src_nid: src_nid, src_ioid: src_ioid, trg_nid: trg_nid, trg_ioid: trg_ioid },\n });\n };\n FuncNodesWorker.prototype.add_external_worker = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var module = _b.module, cls_module = _b.cls_module, cls_name = _b.cls_name;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_external_worker\",\n kwargs: { module: module, cls_module: cls_module, cls_name: cls_name },\n })];\n case 1: return [2 /*return*/, _c.sent()];\n }\n });\n });\n };\n FuncNodesWorker.prototype.sync_local_node_updates = function () {\n var _this = this;\n clearTimeout(this._nodeupdatetimer);\n this._local_nodeupdates.forEach(function (node, id) { return __awaiter(_this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_node\",\n kwargs: { nid: id, data: node },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n }); });\n this._local_nodeupdates.clear();\n this._nodeupdatetimer = setTimeout(function () {\n _this.sync_local_node_updates();\n }, 200);\n };\n FuncNodesWorker.prototype.locally_update_node = function (action) {\n // Add the type to the parameter\n var currentstate = this._local_nodeupdates.get(action.id);\n if (currentstate) {\n var _a = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.deep_merge)(currentstate, action.node), new_obj = _a.new_obj, change = _a.change;\n if (change) {\n this._local_nodeupdates.set(action.id, new_obj);\n }\n }\n else {\n this._local_nodeupdates.set(action.id, action.node);\n }\n if (action.immediate) {\n this.sync_local_node_updates();\n }\n };\n FuncNodesWorker.prototype.get_remote_node_state = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n ans = _a.sent();\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.on_node_action({\n type: \"update\",\n node: ans,\n id: ans.id,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.set_io_value = function (_a) {\n var nid = _a.nid, ioid = _a.ioid, value = _a.value, _b = _a.set_default, set_default = _b === void 0 ? false : _b;\n return this._send_cmd({\n cmd: \"set_io_value\",\n kwargs: { nid: nid, ioid: ioid, value: value, set_default: set_default },\n wait_for_response: true,\n });\n };\n FuncNodesWorker.prototype.clear = function () {\n return this._send_cmd({ cmd: \"clear\" });\n };\n FuncNodesWorker.prototype.save = function () {\n return this._send_cmd({ cmd: \"save\", wait_for_response: true });\n };\n FuncNodesWorker.prototype.load = function (data) {\n var _this = this;\n return this._send_cmd({\n cmd: \"load_data\",\n kwargs: { data: data },\n wait_for_response: true,\n }).then(function () {\n _this.stepwise_fullsync();\n });\n };\n FuncNodesWorker.prototype.get_io_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n value: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_ios_values = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res, mappedres, ioid;\n var nid = _b.nid;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_ios_values\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _c.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n mappedres = {};\n for (ioid in res) {\n mappedres[ioid] = { value: res[ioid] };\n }\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: mappedres,\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype._send_cmd = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var msg, wait_for_response_callback;\n var _this = this;\n var cmd = _b.cmd, kwargs = _b.kwargs, _c = _b.wait_for_response, wait_for_response = _c === void 0 ? true : _c, _d = _b.response_timeout, response_timeout = _d === void 0 ? 5000 : _d, _e = _b.retries, retries = _e === void 0 ? 2 : _e;\n return __generator(this, function (_f) {\n msg = {\n type: \"cmd\",\n cmd: cmd,\n kwargs: kwargs || {},\n };\n if (wait_for_response) {\n if (retries < 0)\n retries = 0;\n wait_for_response_callback = function () { return __awaiter(_this, void 0, void 0, function () {\n var response, _loop_1, this_1, state_1;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _loop_1 = function () {\n var msid, promise, e_2;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n msid = msg.id || (0,uuid__WEBPACK_IMPORTED_MODULE_3__[\"default\"])();\n msg.id = msid;\n promise = new Promise(function (resolve, reject) {\n var timeout = setTimeout(function () {\n reject(\"Timeout@wait_for_response for \" + cmd);\n }, response_timeout);\n _this.messagePromises.set(msid, {\n resolve: function (data) {\n clearTimeout(timeout);\n resolve(data);\n _this.messagePromises.delete(msid);\n },\n reject: function (err) {\n clearTimeout(timeout);\n reject(err);\n _this.messagePromises.delete(msid);\n },\n });\n });\n return [4 /*yield*/, this_1.send(msg)];\n case 1:\n _b.sent();\n _b.label = 2;\n case 2:\n _b.trys.push([2, 4, , 5]);\n return [4 /*yield*/, promise];\n case 3:\n response = _b.sent();\n return [2 /*return*/, \"break\"];\n case 4:\n e_2 = _b.sent();\n if (retries === 0)\n throw e_2;\n retries -= 1;\n return [2 /*return*/, \"continue\"];\n case 5: return [2 /*return*/];\n }\n });\n };\n this_1 = this;\n _a.label = 1;\n case 1:\n if (!(retries >= 0)) return [3 /*break*/, 3];\n return [5 /*yield**/, _loop_1()];\n case 2:\n state_1 = _a.sent();\n if (state_1 === \"break\")\n return [3 /*break*/, 3];\n return [3 /*break*/, 1];\n case 3: return [2 /*return*/, response];\n }\n });\n }); };\n return [2 /*return*/, wait_for_response_callback()];\n }\n return [2 /*return*/, this.send(msg)];\n });\n });\n };\n FuncNodesWorker.prototype.send = function (_data) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n // this is the abstract method that should be implemented by subclasses\n throw new Error(\"Not implemented\");\n });\n });\n };\n FuncNodesWorker.prototype.upload_file = function (_files, _onProgressCallback) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n throw new Error(\"handle_large_message_hint not implemented \");\n });\n });\n };\n FuncNodesWorker.prototype.handle_large_message_hint = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n return __generator(this, function (_c) {\n throw new Error(\"handle_large_message_hint not implemented \");\n });\n });\n };\n FuncNodesWorker.prototype.recieve_workerevent = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0:\n _c = event;\n switch (_c) {\n case \"worker_error\": return [3 /*break*/, 1];\n case \"update_worker_dependencies\": return [3 /*break*/, 2];\n case \"lib_update\": return [3 /*break*/, 3];\n case \"fullsync\": return [3 /*break*/, 5];\n case \"external_worker_update\": return [3 /*break*/, 7];\n }\n return [3 /*break*/, 10];\n case 1:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.logger.error(data.error)];\n case 2:\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n external_worker: data.worker_dependencies,\n })];\n case 3: return [4 /*yield*/, this.sync_lib()];\n case 4:\n _d.sent();\n return [2 /*return*/];\n case 5: return [4 /*yield*/, this.stepwise_fullsync()];\n case 6:\n _d.sent();\n return [2 /*return*/];\n case 7: return [4 /*yield*/, this.sync_lib()];\n case 8:\n _d.sent();\n return [4 /*yield*/, this.sync_external_worker()];\n case 9:\n _d.sent();\n return [2 /*return*/];\n case 10:\n console.warn(\"Unhandled worker event\", event, data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve_nodespace_event = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var _c, _d;\n var event = _b.event, data = _b.data;\n return __generator(this, function (_e) {\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object_size)(data, \"Data size for event \" + event, this._zustand);\n (0,_utils_debugger__WEBPACK_IMPORTED_MODULE_1__.print_object)(data, this._zustand);\n switch (event) {\n case \"after_set_value\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_c = {},\n _c[data.io] = {\n value: data.result,\n },\n _c),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"after_update_value_options\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n io: (_d = {},\n _d[data.io] = {\n value_options: data.result,\n },\n _d),\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerstart\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: true,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"triggerdone\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n in_trigger: false,\n },\n id: data.node,\n from_remote: true,\n })];\n case \"node_trigger_error\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"error\",\n errortype: \"trigger\",\n error: data.error,\n id: data.node,\n from_remote: true,\n })];\n case \"node_removed\":\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"delete\",\n id: data.node,\n from_remote: true,\n })];\n case \"node_added\":\n return [2 /*return*/, this._recieve_node_added(data.node)];\n case \"after_disconnect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_unforward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.on_edge_action({\n type: \"delete\",\n from_remote: true,\n src_nid: data.result[0],\n src_ioid: data.result[1],\n trg_nid: data.result[2],\n trg_ioid: data.result[3],\n })];\n case \"after_connect\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_forward\":\n if (!data.result)\n return [2 /*return*/];\n if (!Array.isArray(data.result))\n return [2 /*return*/];\n if (data.result.length !== 4)\n return [2 /*return*/];\n return [2 /*return*/, this._recieve_edge_added.apply(this, data.result)];\n case \"after_add_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"after_remove_shelf\":\n if (!data.result)\n return [2 /*return*/];\n if (!this._zustand)\n return [2 /*return*/];\n return [2 /*return*/, this._zustand.lib.libstate.getState().set({\n lib: data.result,\n })];\n case \"progress\":\n if (!this._zustand)\n return [2 /*return*/];\n if (data.node) {\n return [2 /*return*/, this._zustand.on_node_action({\n type: \"update\",\n node: {\n id: data.node,\n progress: data.info,\n },\n id: data.node,\n from_remote: true,\n })];\n }\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n default:\n console.warn(\"Unhandled nodepsace event\", event, data);\n break;\n }\n return [2 /*return*/];\n });\n });\n };\n FuncNodesWorker.prototype.add_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"add_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_lib = function (lib) {\n return __awaiter(this, void 0, void 0, function () {\n var ans;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_package_dependency\",\n kwargs: { name: lib },\n wait_for_response: false,\n })];\n case 1:\n ans = _a.sent();\n return [2 /*return*/, ans];\n }\n });\n });\n };\n FuncNodesWorker.prototype.recieve = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var promise, _a;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n _a = data.type;\n switch (_a) {\n case \"nsevent\": return [3 /*break*/, 1];\n case \"result\": return [3 /*break*/, 3];\n case \"error\": return [3 /*break*/, 4];\n case \"progress\": return [3 /*break*/, 5];\n case \"workerevent\": return [3 /*break*/, 6];\n case \"large_message\": return [3 /*break*/, 8];\n }\n return [3 /*break*/, 10];\n case 1: return [4 /*yield*/, this.recieve_nodespace_event(data)];\n case 2: return [2 /*return*/, _b.sent()];\n case 3:\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.resolve(data.result)];\n }\n return [3 /*break*/, 11];\n case 4:\n this.on_error(data.tb + \"\\n\" + data.error);\n promise = data.id && this.messagePromises.get(data.id);\n if (promise) {\n return [2 /*return*/, promise.reject(data.error)];\n }\n return [3 /*break*/, 11];\n case 5:\n if (!this._zustand)\n return [2 /*return*/];\n this._zustand.set_progress(data);\n return [3 /*break*/, 11];\n case 6: return [4 /*yield*/, this.recieve_workerevent(data)];\n case 7: return [2 /*return*/, _b.sent()];\n case 8: return [4 /*yield*/, this.handle_large_message_hint(data)];\n case 9: return [2 /*return*/, _b.sent()];\n case 10:\n console.warn(\"Unhandled message\", data);\n return [3 /*break*/, 11];\n case 11: return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.disconnect = function () { };\n FuncNodesWorker.prototype.onclose = function () {\n this.is_open = false;\n if (!this._zustand)\n return;\n this._zustand.auto_progress();\n };\n FuncNodesWorker.prototype.reconnect = function () {\n return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {\n return [2 /*return*/];\n }); });\n };\n FuncNodesWorker.prototype.stop = function () {\n return __awaiter(this, void 0, void 0, function () {\n var oldonclose;\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({ cmd: \"stop_worker\", wait_for_response: false })];\n case 1:\n _a.sent();\n oldonclose = this.onclose.bind(this);\n this.onclose = function () {\n oldonclose();\n if (!_this._zustand)\n return;\n if (_this._zustand.worker === _this) {\n _this._zustand.clear_all();\n }\n _this.onclose = oldonclose;\n };\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_io_full_value = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_io_full_value\",\n kwargs: { nid: nid, ioid: ioid },\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = {\n fullvalue: res,\n },\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_io_options = function (_a) {\n return __awaiter(this, arguments, void 0, function (_b) {\n var res;\n var _c;\n var nid = _b.nid, ioid = _b.ioid, options = _b.options;\n return __generator(this, function (_d) {\n switch (_d.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_io_options\",\n kwargs: __assign({ nid: nid, ioid: ioid }, options),\n wait_for_response: true,\n })];\n case 1:\n res = _d.sent();\n if (!this._zustand)\n return [2 /*return*/, res];\n this._zustand.on_node_action({\n type: \"update\",\n node: {\n io: (_c = {},\n _c[ioid] = __assign({}, options),\n _c),\n },\n id: nid,\n from_remote: true,\n });\n return [2 /*return*/];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_node_status = function (nid) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_node_state\",\n kwargs: { nid: nid },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.get_available_modules = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"get_available_modules\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_external_worker = function (worker_id, class_id, data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_external_worker\",\n kwargs: __assign({ worker_id: worker_id, class_id: class_id }, data),\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.remove_external_worker = function (worker_id, class_id) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"remove_external_worker\",\n kwargs: { worker_id: worker_id, class_id: class_id },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.export = function () {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"export_worker\",\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n return [2 /*return*/, res];\n }\n });\n });\n };\n FuncNodesWorker.prototype.update_from_export = function (data) {\n return __awaiter(this, void 0, void 0, function () {\n var res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4 /*yield*/, this._send_cmd({\n cmd: \"update_from_export\",\n kwargs: { data: data },\n wait_for_response: true,\n })];\n case 1:\n res = _a.sent();\n this.stepwise_fullsync();\n return [2 /*return*/, res];\n }\n });\n });\n };\n return FuncNodesWorker;\n}());\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (FuncNodesWorker);\n\n\n//# sourceURL=webpack://FuncNodesReact/./src/funcnodes/funcnodesworker.ts?");
3167
3167
 
3168
3168
  /***/ }),
3169
3169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linkdlab/funcnodes_react_flow",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Frontend with React Flow for FuncNodes",
5
5
  "repository": {
6
6
  "type": "git",