-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved type safety, added retry file prompt, added multiple file pr…
…ompts in one flow
- Loading branch information
1 parent
418293d
commit 0e71ed9
Showing
98 changed files
with
2,868 additions
and
883 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
import VisualisationEngine from './abstractions/visualisation_engine'; | ||
export declare const Assembly: (worker: Worker) => VisualisationEngine; | ||
import { VisualisationEngine, ProcessingEngine, System } from './types/modules'; | ||
import CommandRouter from './command_router'; | ||
export default class Assembly { | ||
visualisationEngine: VisualisationEngine; | ||
processingEngine: ProcessingEngine; | ||
router: CommandRouter; | ||
constructor(worker: Worker, system: System); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import ReactEngine from './visualisation/react/engine'; | ||
import ReactFactory from './visualisation/react/factory'; | ||
import WorkerProcessingEngine from './processing/worker_engine'; | ||
export var Assembly = function (worker) { | ||
var processingEngine = new WorkerProcessingEngine(worker); | ||
var visualisationEngine = new ReactEngine(new ReactFactory(), processingEngine); | ||
processingEngine.eventListener = visualisationEngine.onEvent; | ||
return visualisationEngine; | ||
}; | ||
import CommandRouter from './command_router'; | ||
var Assembly = /** @class */ (function () { | ||
function Assembly(worker, system) { | ||
this.visualisationEngine = new ReactEngine(new ReactFactory()); | ||
this.router = new CommandRouter(system, this.visualisationEngine); | ||
this.processingEngine = new WorkerProcessingEngine(worker, this.router); | ||
} | ||
return Assembly; | ||
}()); | ||
export default Assembly; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Command, Response, CommandUI, CommandSystem } from './types/commands'; | ||
import { CommandHandler, System, VisualisationEngine } from './types/modules'; | ||
export default class CommandRouter implements CommandHandler { | ||
system: System; | ||
visualisationEngine: VisualisationEngine; | ||
constructor(system: System, visualisationEngine: VisualisationEngine); | ||
onCommand(command: Command): Promise<Response>; | ||
onCommandSystem(command: CommandSystem, resolve: (response: Response) => void): void; | ||
onCommandUI(command: CommandUI, reject: (reason?: any) => void): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
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; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import { isCommandSystem, isCommandUI } from './types/commands'; | ||
var CommandRouter = /** @class */ (function () { | ||
function CommandRouter(system, visualisationEngine) { | ||
this.system = system; | ||
this.visualisationEngine = visualisationEngine; | ||
} | ||
CommandRouter.prototype.onCommand = function (command) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
if (isCommandSystem(command)) { | ||
_this.onCommandSystem(command, resolve); | ||
} | ||
else if (isCommandUI(command)) { | ||
_this.onCommandUI(command, resolve); | ||
} | ||
else { | ||
reject(new TypeError('Unknown command' + JSON.stringify(command))); | ||
} | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CommandRouter.prototype.onCommandSystem = function (command, resolve) { | ||
this.system.send(command); | ||
resolve({ command: command, payload: { __type__: 'PayloadVoid', value: undefined } }); | ||
}; | ||
CommandRouter.prototype.onCommandUI = function (command, reject) { | ||
this.visualisationEngine.render(command).then(function (response) { reject(response); }, function () { }); | ||
}; | ||
return CommandRouter; | ||
}()); | ||
export default CommandRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Omit } from 'lodash'; | ||
export declare const childOf: (arg: any, superType: string) => boolean; | ||
export declare const instanceOf: <T>(arg: any, properties: (keyof T)[]) => arg is T; | ||
export declare type Weak<T> = Omit<T, '__type__'>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export var childOf = function (arg, superType) { | ||
var _a; | ||
return (_a = arg === null || arg === void 0 ? void 0 : arg.__type__) === null || _a === void 0 ? void 0 : _a.startsWith(superType); | ||
}; | ||
export var instanceOf = function (arg, properties) { | ||
return !properties.some(function (property) { return arg[property] === undefined; }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
declare function runCycle(userInput: any): void; | ||
declare function runCycle(payload: any): void; | ||
declare function unwrap(response: any): Promise<any>; | ||
declare function copyFileToPyFS(file: any, resolve: any): void; | ||
declare function initialise(): any; | ||
declare function loadScript(script: any): void; | ||
declare function pyWorker(): string; | ||
declare let pyScript: any; | ||
declare const pyPortApi: "\nclass Event:\n def toDict(self):\n return setType({}, \"Event\")\n\n\nclass EndOfFlow(Event):\n __slots__ = \"result\"\n def __init__(self, result):\n self.result = result\n def translate_result(self):\n print(\"translate\")\n data_output = []\n for data in self.result:\n df = data[\"data_frame\"]\n data_output.append({\"id\": data[\"id\"], \"data_frame\": df.to_json()})\n return {\n \"title\": data[\"title\"],\n \"data\": data_output,\n }\n def toDict(self):\n print(\"toDict2\")\n dict = toDict(super(), \"EndOfFlow\") \n dict = dict | self.translate_result()\n return dict\n \n\nclass Command(Event):\n def toDict(self):\n return toDict(super(), \"Command\")\n\n\nclass Prompt(Command):\n __slots__ = \"title\", \"description\"\n def __init__(self, title, description):\n self.title = title\n self.description = description\n def toDict(self):\n dict = toDict(super(), \"Prompt\")\n dict[\"title\"] = self.title.toDict()\n dict[\"description\"] = self.description.toDict()\n return dict\n\n\nclass FileInput(Prompt):\n __slots__ = \"extensions\"\n def __init__(self, title, description, extensions):\n super().__init__(title, description)\n self.extensions = extensions\n def toDict(self):\n dict = toDict(super(), \"FileInput\")\n dict[\"extensions\"] = self.extensions\n return dict\n\n\nclass RadioInput(Prompt):\n def __init__(self, title, description, items):\n super().__init__(title, description)\n self.items = items\n def toDict(self):\n dict = toDict(super(), \"RadioInput\")\n dict[\"items\"] = self.items\n return dict\n\n\nclass Translatable:\n __slots__ = \"translations\"\n def __init__(self):\n self.translations = {}\n def add(self, locale, text):\n self.translations[locale] = text\n return self\n def toDict(self):\n return setType(self.translations, \"Translatable\")\n\n\ndef toDict(zuper, type):\n return setType(zuper.toDict(), type)\n\n\ndef setType(dict, type):\n key = \"__type__\"\n seperator = \".\"\n\n path = [type]\n if key in dict:\n path.insert(0, dict[key])\n dict[key] = seperator.join(path)\n return dict\n"; | ||
declare const pyPortApi: "\nclass CommandUIRender:\n __slots__ = \"page\"\n def __init__(self, page):\n self.page = page\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"CommandUIRender\"\n dict[\"page\"] = self.page.toDict()\n return dict\n\nclass CommandSystemDonate:\n __slots__ = \"key\", \"data\"\n def __init__(self, key, data):\n self.key = key\n self.data = data\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"CommandSystemDonate\"\n dict[\"key\"] = self.key\n dict[\"data\"] = self.data\n return dict\n\n\nclass PropsUIHeader:\n __slots__ = \"title\"\n def __init__(self, title):\n self.title = title\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIHeader\"\n dict[\"title\"] = self.title.toDict()\n return dict\n\n\nclass PropsUIPromptConfirm:\n __slots__ = \"text\", \"ok\", \"cancel\"\n def __init__(self, text, ok, cancel):\n self.text = text\n self.ok = ok\n self.cancel = cancel\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPromptConfirm\"\n dict[\"text\"] = self.text.toDict()\n dict[\"ok\"] = self.ok.toDict()\n dict[\"cancel\"] = self.cancel.toDict()\n return dict\n\n\nclass PropsUISpinner:\n __slots__ = \"text\"\n def __init__(self, text):\n self.text = text\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUISpinner\"\n dict[\"text\"] = self.text.toDict()\n return dict\n\n\nclass PropsUIPromptConsentForm:\n __slots__ = \"title\", \"description\", \"tables\"\n def __init__(self, title, description, tables):\n self.title = title\n self.description = description \n self.tables = tables\n def translate_tables(self):\n tables_output = []\n for table in self.tables:\n tables_output.append(table.toDict())\n return tables_output\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPromptConsentForm\"\n dict[\"title\"] = self.title.toDict()\n dict[\"description\"] = self.description.toDict()\n dict[\"tables\"] = self.translate_tables()\n return dict\n\n\nclass PropsUIPromptConsentFormTable:\n __slots__ = \"id\", \"title\", \"data_frame\"\n def __init__(self, id, title, data_frame):\n self.id = id\n self.title = title\n self.data_frame = data_frame\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPromptConsentFormTable\"\n dict[\"id\"] = self.id\n dict[\"title\"] = self.title\n dict[\"data_frame\"] = self.data_frame.to_json()\n return dict\n\n\nclass PropsUIPromptFileInput:\n __slots__ = \"title\", \"description\", \"extensions\"\n def __init__(self, title, description, extensions):\n self.title = title\n self.description = description\n self.extensions = extensions\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPromptFileInput\"\n dict[\"title\"] = self.title.toDict()\n dict[\"description\"] = self.description.toDict()\n dict[\"extensions\"] = self.extensions\n return dict\n\n\nclass PropsUIPromptRadioInput:\n __slots__ = \"title\", \"description\", \"items\"\n def __init__(self, title, description, items):\n self.title = title\n self.description = description\n self.items = items\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPromptRadioInput\"\n dict[\"title\"] = self.title.toDict()\n dict[\"description\"] = self.description.toDict()\n dict[\"items\"] = self.items\n return dict\n\n\nclass PropsUIPageDonation:\n __slots__ = \"header\", \"body\", \"spinner\"\n def __init__(self, header, body, spinner):\n self.header = header\n self.body = body\n self.spinner = spinner\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPageDonation\"\n dict[\"header\"] = self.header.toDict()\n dict[\"body\"] = self.body.toDict()\n dict[\"spinner\"] = self.spinner.toDict()\n return dict\n\n\nclass PropsUIPageStart:\n __slots__ = \"header\", \"spinner\"\n def __init__(self, header, spinner):\n self.header = header\n self.spinner = spinner\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPageStart\"\n dict[\"header\"] = self.header.toDict()\n dict[\"spinner\"] = self.spinner.toDict()\n return dict\n\n\nclass PropsUIPageEnd:\n __slots__ = \"header\" \n def __init__(self, header):\n self.header = header\n def toDict(self):\n dict = {}\n dict[\"__type__\"] = \"PropsUIPageEnd\"\n dict[\"header\"] = self.header.toDict()\n return dict\n\n\nclass Translatable:\n __slots__ = \"translations\"\n def __init__(self, translations):\n self.translations = translations\n def toDict(self):\n dict = {}\n dict[\"translations\"] = self.translations\n return dict \n"; |
Oops, something went wrong.