@dodona/papyros 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Library.d.ts +11 -0
- package/dist/Library.js +11 -0
- package/dist/Library.js.map +1 -0
- package/dist/ProgrammingLanguage.d.ts +7 -0
- package/dist/ProgrammingLanguage.js +9 -0
- package/dist/ProgrammingLanguage.js.map +1 -0
- package/dist/backend/Backend.d.ts +92 -0
- package/dist/backend/Backend.js +79 -0
- package/dist/backend/Backend.js.map +1 -0
- package/dist/backend/workers/javascript/JavaScriptWorker.d.ts +39 -0
- package/dist/backend/workers/javascript/JavaScriptWorker.js +158 -0
- package/dist/backend/workers/javascript/JavaScriptWorker.js.map +1 -0
- package/dist/backend/workers/javascript/worker.d.ts +1 -0
- package/dist/backend/workers/javascript/worker.js +5 -0
- package/dist/backend/workers/javascript/worker.js.map +1 -0
- package/dist/backend/workers/python/PythonWorker.d.ts +32 -0
- package/dist/backend/workers/python/PythonWorker.js +117 -0
- package/dist/backend/workers/python/PythonWorker.js.map +1 -0
- package/dist/backend/workers/python/python_package.tar.gz.load_by_url +0 -0
- package/dist/backend/workers/python/worker.d.ts +1 -0
- package/dist/backend/workers/python/worker.js +5 -0
- package/dist/backend/workers/python/worker.js.map +1 -0
- package/dist/communication/BackendEvent.d.ts +33 -0
- package/dist/communication/BackendEvent.js +18 -0
- package/dist/communication/BackendEvent.js.map +1 -0
- package/dist/communication/BackendEventQueue.d.ts +59 -0
- package/dist/communication/BackendEventQueue.js +96 -0
- package/dist/communication/BackendEventQueue.js.map +1 -0
- package/dist/communication/BackendManager.d.ts +68 -0
- package/dist/communication/BackendManager.js +99 -0
- package/dist/communication/BackendManager.js.map +1 -0
- package/dist/communication/InputServiceWorker.d.ts +1 -0
- package/dist/communication/InputServiceWorker.js +37 -0
- package/dist/communication/InputServiceWorker.js.map +1 -0
- package/dist/communication/InputWorker.d.ts +22 -0
- package/dist/communication/InputWorker.js +63 -0
- package/dist/communication/InputWorker.js.map +1 -0
- package/dist/frontend/components/CodeRunner.d.ts +9 -0
- package/dist/frontend/components/CodeRunner.js +60 -0
- package/dist/frontend/components/CodeRunner.js.map +1 -0
- package/dist/frontend/components/Debugger.d.ts +7 -0
- package/dist/frontend/components/Debugger.js +75 -0
- package/dist/frontend/components/Debugger.js.map +1 -0
- package/dist/frontend/components/Input.d.ts +13 -0
- package/dist/frontend/components/Input.js +60 -0
- package/dist/frontend/components/Input.js.map +1 -0
- package/dist/frontend/components/Output.d.ts +14 -0
- package/dist/frontend/components/Output.js +157 -0
- package/dist/frontend/components/Output.js.map +1 -0
- package/dist/frontend/components/PapyrosElement.d.ts +8 -0
- package/dist/frontend/components/PapyrosElement.js +24 -0
- package/dist/frontend/components/PapyrosElement.js.map +1 -0
- package/dist/frontend/components/app/App.d.ts +24 -0
- package/dist/frontend/components/app/App.js +207 -0
- package/dist/frontend/components/app/App.js.map +1 -0
- package/dist/frontend/components/app/ExamplePicker.d.ts +7 -0
- package/dist/frontend/components/app/ExamplePicker.js +36 -0
- package/dist/frontend/components/app/ExamplePicker.js.map +1 -0
- package/dist/frontend/components/app/LanguagePicker.d.ts +7 -0
- package/dist/frontend/components/app/LanguagePicker.js +33 -0
- package/dist/frontend/components/app/LanguagePicker.js.map +1 -0
- package/dist/frontend/components/app/ProgrammingLanguagePicker.d.ts +7 -0
- package/dist/frontend/components/app/ProgrammingLanguagePicker.js +38 -0
- package/dist/frontend/components/app/ProgrammingLanguagePicker.js.map +1 -0
- package/dist/frontend/components/app/examples/JavaScriptExamples.d.ts +5 -0
- package/dist/frontend/components/app/examples/JavaScriptExamples.js +16 -0
- package/dist/frontend/components/app/examples/JavaScriptExamples.js.map +1 -0
- package/dist/frontend/components/app/examples/PythonExamples.d.ts +14 -0
- package/dist/frontend/components/app/examples/PythonExamples.js +163 -0
- package/dist/frontend/components/app/examples/PythonExamples.js.map +1 -0
- package/dist/frontend/components/app/themes/ThemePicker.d.ts +11 -0
- package/dist/frontend/components/app/themes/ThemePicker.js +48 -0
- package/dist/frontend/components/app/themes/ThemePicker.js.map +1 -0
- package/dist/frontend/components/app/themes/ThemedButton.d.ts +9 -0
- package/dist/frontend/components/app/themes/ThemedButton.js +53 -0
- package/dist/frontend/components/app/themes/ThemedButton.js.map +1 -0
- package/dist/frontend/components/code_mirror/BatchInputEditor.d.ts +8 -0
- package/dist/frontend/components/code_mirror/BatchInputEditor.js +51 -0
- package/dist/frontend/components/code_mirror/BatchInputEditor.js.map +1 -0
- package/dist/frontend/components/code_mirror/CodeEditor.d.ts +24 -0
- package/dist/frontend/components/code_mirror/CodeEditor.js +204 -0
- package/dist/frontend/components/code_mirror/CodeEditor.js.map +1 -0
- package/dist/frontend/components/code_mirror/CodeMirrorEditor.d.ts +22 -0
- package/dist/frontend/components/code_mirror/CodeMirrorEditor.js +111 -0
- package/dist/frontend/components/code_mirror/CodeMirrorEditor.js.map +1 -0
- package/dist/frontend/components/code_mirror/Extensions.d.ts +15 -0
- package/dist/frontend/components/code_mirror/Extensions.js +164 -0
- package/dist/frontend/components/code_mirror/Extensions.js.map +1 -0
- package/dist/frontend/components/code_mirror/MaterialTheme.d.ts +5 -0
- package/dist/frontend/components/code_mirror/MaterialTheme.js +115 -0
- package/dist/frontend/components/code_mirror/MaterialTheme.js.map +1 -0
- package/dist/frontend/components/code_runner/ButtonLint.d.ts +9 -0
- package/dist/frontend/components/code_runner/ButtonLint.js +72 -0
- package/dist/frontend/components/code_runner/ButtonLint.js.map +1 -0
- package/dist/frontend/components/code_runner/Code.d.ts +7 -0
- package/dist/frontend/components/code_runner/Code.js +48 -0
- package/dist/frontend/components/code_runner/Code.js.map +1 -0
- package/dist/frontend/components/code_runner/RunState.d.ts +7 -0
- package/dist/frontend/components/code_runner/RunState.js +41 -0
- package/dist/frontend/components/code_runner/RunState.js.map +1 -0
- package/dist/frontend/components/input/BatchInput.d.ts +9 -0
- package/dist/frontend/components/input/BatchInput.js +53 -0
- package/dist/frontend/components/input/BatchInput.js.map +1 -0
- package/dist/frontend/components/input/InteractiveInput.d.ts +13 -0
- package/dist/frontend/components/input/InteractiveInput.js +71 -0
- package/dist/frontend/components/input/InteractiveInput.js.map +1 -0
- package/dist/frontend/state/Constants.d.ts +38 -0
- package/dist/frontend/state/Constants.js +111 -0
- package/dist/frontend/state/Constants.js.map +1 -0
- package/dist/frontend/state/Debugger.d.ts +23 -0
- package/dist/frontend/state/Debugger.js +86 -0
- package/dist/frontend/state/Debugger.js.map +1 -0
- package/dist/frontend/state/Examples.d.ts +11 -0
- package/dist/frontend/state/Examples.js +36 -0
- package/dist/frontend/state/Examples.js.map +1 -0
- package/dist/frontend/state/I18n.d.ts +16 -0
- package/dist/frontend/state/I18n.js +75 -0
- package/dist/frontend/state/I18n.js.map +1 -0
- package/dist/frontend/state/InputOutput.d.ts +64 -0
- package/dist/frontend/state/InputOutput.js +146 -0
- package/dist/frontend/state/InputOutput.js.map +1 -0
- package/dist/frontend/state/Papyros.d.ts +40 -0
- package/dist/frontend/state/Papyros.js +115 -0
- package/dist/frontend/state/Papyros.js.map +1 -0
- package/dist/frontend/state/Runner.d.ts +123 -0
- package/dist/frontend/state/Runner.js +372 -0
- package/dist/frontend/state/Runner.js.map +1 -0
- package/dist/frontend/state/Test.d.ts +10 -0
- package/dist/frontend/state/Test.js +43 -0
- package/dist/frontend/state/Test.js.map +1 -0
- package/dist/frontend/state/Translations.d.ts +178 -0
- package/dist/frontend/state/Translations.js +187 -0
- package/dist/frontend/state/Translations.js.map +1 -0
- package/dist/frontend/state/themes/blue-dark.d.ts +2 -0
- package/dist/frontend/state/themes/blue-dark.js +56 -0
- package/dist/frontend/state/themes/blue-dark.js.map +1 -0
- package/dist/frontend/state/themes/blue-light.d.ts +2 -0
- package/dist/frontend/state/themes/blue-light.js +56 -0
- package/dist/frontend/state/themes/blue-light.js.map +1 -0
- package/dist/frontend/state/themes/green-dark.d.ts +2 -0
- package/dist/frontend/state/themes/green-dark.js +56 -0
- package/dist/frontend/state/themes/green-dark.js.map +1 -0
- package/dist/frontend/state/themes/green-light.d.ts +2 -0
- package/dist/frontend/state/themes/green-light.js +56 -0
- package/dist/frontend/state/themes/green-light.js.map +1 -0
- package/dist/frontend/state/themes/red-dark.d.ts +2 -0
- package/dist/frontend/state/themes/red-dark.js +56 -0
- package/dist/frontend/state/themes/red-dark.js.map +1 -0
- package/dist/frontend/state/themes/red-light.d.ts +2 -0
- package/dist/frontend/state/themes/red-light.js +56 -0
- package/dist/frontend/state/themes/red-light.js.map +1 -0
- package/dist/util/Logging.d.ts +15 -0
- package/dist/util/Logging.js +30 -0
- package/dist/util/Logging.js.map +1 -0
- package/dist/util/Util.d.ts +8 -0
- package/dist/util/Util.js +48 -0
- package/dist/util/Util.js.map +1 -0
- package/package.json +1 -1
- package/dist/assets/__vite-browser-external-9wXp6ZBx.js +0 -1
- package/dist/assets/__vite-browser-external-BIHI7g3E.js +0 -1
- package/dist/assets/index-C1AWjGcU.js +0 -2202
- package/dist/assets/manifest-BaVmi6rC.json +0 -15
- package/dist/assets/python_package.tar.gz-B8aMWvGt.load_by_url +0 -0
- package/dist/assets/worker-BhABRh01.js +0 -5
- package/dist/assets/worker-C2Ju1j5g.js +0 -110
- package/dist/index.html +0 -26
- package/dist/manifest.json +0 -15
- package/dist/robots.txt +0 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./frontend/components/Input";
|
|
2
|
+
import "./frontend/components/Output";
|
|
3
|
+
import "./frontend/components/CodeRunner";
|
|
4
|
+
import "./frontend/components/Debugger";
|
|
5
|
+
import { Papyros, papyros } from "./frontend/state/Papyros";
|
|
6
|
+
import { InputMode } from "./frontend/state/InputOutput";
|
|
7
|
+
import { RunMode } from "./backend/Backend";
|
|
8
|
+
import { ProgrammingLanguage } from "./ProgrammingLanguage";
|
|
9
|
+
import { OutputType, FriendlyError } from "./frontend/state/InputOutput";
|
|
10
|
+
export { Papyros, InputMode, RunMode, ProgrammingLanguage, OutputType, papyros };
|
|
11
|
+
export type { FriendlyError };
|
package/dist/Library.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./frontend/components/Input";
|
|
2
|
+
import "./frontend/components/Output";
|
|
3
|
+
import "./frontend/components/CodeRunner";
|
|
4
|
+
import "./frontend/components/Debugger";
|
|
5
|
+
import { Papyros, papyros } from "./frontend/state/Papyros";
|
|
6
|
+
import { InputMode } from "./frontend/state/InputOutput";
|
|
7
|
+
import { RunMode } from "./backend/Backend";
|
|
8
|
+
import { ProgrammingLanguage } from "./ProgrammingLanguage";
|
|
9
|
+
import { OutputType } from "./frontend/state/InputOutput";
|
|
10
|
+
export { Papyros, InputMode, RunMode, ProgrammingLanguage, OutputType, papyros };
|
|
11
|
+
//# sourceMappingURL=Library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Library.js","sourceRoot":"","sources":["../src/Library.ts"],"names":[],"mappings":"AAAA,OAAO,6BAA6B,CAAC;AACrC,OAAO,8BAA8B,CAAC;AACtC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAiB,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String enum representing programming languages supported by Papyros
|
|
3
|
+
*/
|
|
4
|
+
export var ProgrammingLanguage;
|
|
5
|
+
(function (ProgrammingLanguage) {
|
|
6
|
+
ProgrammingLanguage["Python"] = "Python";
|
|
7
|
+
ProgrammingLanguage["JavaScript"] = "JavaScript";
|
|
8
|
+
})(ProgrammingLanguage || (ProgrammingLanguage = {}));
|
|
9
|
+
//# sourceMappingURL=ProgrammingLanguage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgrammingLanguage.js","sourceRoot":"","sources":["../src/ProgrammingLanguage.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC3B,wCAAiB,CAAA;IACjB,gDAAyB,CAAA;AAC7B,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BackendEvent } from "../communication/BackendEvent";
|
|
2
|
+
import { SyncExtras } from "comsync";
|
|
3
|
+
import { BackendEventQueue } from "../communication/BackendEventQueue";
|
|
4
|
+
export interface WorkerDiagnostic {
|
|
5
|
+
/**
|
|
6
|
+
* 1-based index of the starting line containing the issue
|
|
7
|
+
*/
|
|
8
|
+
lineNr: number;
|
|
9
|
+
/**
|
|
10
|
+
* 0-based index of the column in the starting line
|
|
11
|
+
*/
|
|
12
|
+
columnNr: number;
|
|
13
|
+
/**
|
|
14
|
+
* 1-based index of the ending line containing the issue
|
|
15
|
+
* Can be the same as lineNr
|
|
16
|
+
*/
|
|
17
|
+
endLineNr: number;
|
|
18
|
+
/**
|
|
19
|
+
* 0-based index of the column in the ending line
|
|
20
|
+
*/
|
|
21
|
+
endColumnNr: number;
|
|
22
|
+
/**
|
|
23
|
+
* Severity of the issue
|
|
24
|
+
*/
|
|
25
|
+
severity: "info" | "warning" | "error";
|
|
26
|
+
/**
|
|
27
|
+
* Message describing the issue
|
|
28
|
+
*/
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
export declare enum RunMode {
|
|
32
|
+
Run = "run",
|
|
33
|
+
Debug = "debug",
|
|
34
|
+
Doctest = "doctest"
|
|
35
|
+
}
|
|
36
|
+
export declare abstract class Backend<Extras extends SyncExtras = SyncExtras> {
|
|
37
|
+
/**
|
|
38
|
+
* SyncExtras object that grants access to helpful methods
|
|
39
|
+
* for synchronous operations
|
|
40
|
+
*/
|
|
41
|
+
protected extras: Extras;
|
|
42
|
+
/**
|
|
43
|
+
* Callback to handle events published by this Backend
|
|
44
|
+
*/
|
|
45
|
+
protected onEvent: (e: BackendEvent) => any;
|
|
46
|
+
/**
|
|
47
|
+
* Queue to handle published events without overloading the thread
|
|
48
|
+
*/
|
|
49
|
+
protected queue: BackendEventQueue;
|
|
50
|
+
/**
|
|
51
|
+
* Constructor is limited as it is meant to be used as a WebWorker
|
|
52
|
+
* Proper initialization occurs in the launch method when the worker is started
|
|
53
|
+
* Synchronously exposing methods should be done here
|
|
54
|
+
*/
|
|
55
|
+
constructor();
|
|
56
|
+
/**
|
|
57
|
+
* @return {any} The function to expose methods for Comsync to allow interrupting
|
|
58
|
+
*/
|
|
59
|
+
protected syncExpose(): any;
|
|
60
|
+
/**
|
|
61
|
+
* Initialize the backend by doing all setup-related work
|
|
62
|
+
* @param {function(BackendEvent):void} onEvent Callback for when events occur
|
|
63
|
+
* @return {Promise<void>} Promise of launching
|
|
64
|
+
*/
|
|
65
|
+
launch(onEvent: (e: BackendEvent) => void): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Determine whether the modes supported by this Backend are active
|
|
68
|
+
* @param {string} code The current code in the editor
|
|
69
|
+
* @return {Array<RunMode>} The run modes of this Backend
|
|
70
|
+
*/
|
|
71
|
+
runModes(code: string): Array<RunMode>;
|
|
72
|
+
/**
|
|
73
|
+
* Executes the given code
|
|
74
|
+
* @param {Extras} extras Helper properties to run code
|
|
75
|
+
* @param {string} code The code to run
|
|
76
|
+
* @param {string} mode The mode to run the code in
|
|
77
|
+
* @return {Promise<void>} Promise of execution
|
|
78
|
+
*/
|
|
79
|
+
abstract runCode(extras: Extras, code: string, mode?: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Generate linting suggestions for the given code
|
|
82
|
+
* @param {string} code The code to lint
|
|
83
|
+
*/
|
|
84
|
+
abstract lintCode(code: string): Promise<Array<WorkerDiagnostic>>;
|
|
85
|
+
/**
|
|
86
|
+
* Provide files to be used by the backend
|
|
87
|
+
* @param {Record<string, string>} inlineFiles Map of file names to their contents
|
|
88
|
+
* @param {Record<string, string>} hrefFiles Map of file names to URLS with their contents
|
|
89
|
+
* @return {Promise<void>} Resolves when the files are present in the backend
|
|
90
|
+
*/
|
|
91
|
+
provideFiles(inlineFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { BackendEventType } from "../communication/BackendEvent";
|
|
11
|
+
import { syncExpose } from "comsync";
|
|
12
|
+
import { BackendEventQueue } from "../communication/BackendEventQueue";
|
|
13
|
+
export var RunMode;
|
|
14
|
+
(function (RunMode) {
|
|
15
|
+
RunMode["Run"] = "run";
|
|
16
|
+
RunMode["Debug"] = "debug";
|
|
17
|
+
RunMode["Doctest"] = "doctest";
|
|
18
|
+
})(RunMode || (RunMode = {}));
|
|
19
|
+
export class Backend {
|
|
20
|
+
/**
|
|
21
|
+
* Constructor is limited as it is meant to be used as a WebWorker
|
|
22
|
+
* Proper initialization occurs in the launch method when the worker is started
|
|
23
|
+
* Synchronously exposing methods should be done here
|
|
24
|
+
*/
|
|
25
|
+
constructor() {
|
|
26
|
+
this.extras = {};
|
|
27
|
+
this.onEvent = () => {
|
|
28
|
+
// Empty, initialized in launch
|
|
29
|
+
};
|
|
30
|
+
this.runCode = this.syncExpose()(this.runCode.bind(this));
|
|
31
|
+
this.queue = {};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @return {any} The function to expose methods for Comsync to allow interrupting
|
|
35
|
+
*/
|
|
36
|
+
syncExpose() {
|
|
37
|
+
return syncExpose;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Initialize the backend by doing all setup-related work
|
|
41
|
+
* @param {function(BackendEvent):void} onEvent Callback for when events occur
|
|
42
|
+
* @return {Promise<void>} Promise of launching
|
|
43
|
+
*/
|
|
44
|
+
launch(onEvent) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
this.onEvent = (e) => {
|
|
47
|
+
onEvent(e);
|
|
48
|
+
if (e.type === BackendEventType.Sleep) {
|
|
49
|
+
return this.extras.syncSleep(e.data);
|
|
50
|
+
}
|
|
51
|
+
else if (e.type === BackendEventType.Input) {
|
|
52
|
+
return this.extras.readMessage();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
this.queue = new BackendEventQueue(this.onEvent.bind(this));
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Determine whether the modes supported by this Backend are active
|
|
61
|
+
* @param {string} code The current code in the editor
|
|
62
|
+
* @return {Array<RunMode>} The run modes of this Backend
|
|
63
|
+
*/
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
65
|
+
runModes(code) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Provide files to be used by the backend
|
|
70
|
+
* @param {Record<string, string>} inlineFiles Map of file names to their contents
|
|
71
|
+
* @param {Record<string, string>} hrefFiles Map of file names to URLS with their contents
|
|
72
|
+
* @return {Promise<void>} Resolves when the files are present in the backend
|
|
73
|
+
*/
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
|
+
provideFiles(inlineFiles, hrefFiles) {
|
|
76
|
+
return Promise.resolve();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=Backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Backend.js","sourceRoot":"","sources":["../../src/backend/Backend.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAc,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AA8BvE,MAAM,CAAN,IAAY,OAIX;AAJD,WAAY,OAAO;IACf,sBAAW,CAAA;IACX,0BAAe,CAAA;IACf,8BAAmB,CAAA;AACvB,CAAC,EAJW,OAAO,KAAP,OAAO,QAIlB;AAED,MAAM,OAAgB,OAAO;IAczB;;;;OAIG;IACH;QACI,IAAI,CAAC,MAAM,GAAG,EAAY,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE;YAChB,+BAA+B;QACnC,CAAC,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,GAAG,EAAuB,CAAC;IACzC,CAAC;IAED;;OAEG;IACO,UAAU;QAChB,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACU,MAAM,CAAC,OAAkC;;YAClD,IAAI,CAAC,OAAO,GAAG,CAAC,CAAe,EAAE,EAAE;gBAC/B,OAAO,CAAC,CAAC,CAAC,CAAC;gBACX,IAAI,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAAC,KAAK,EAAE,CAAC;oBACpC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBACzC,CAAC;qBAAM,IAAI,CAAC,CAAC,IAAI,KAAK,gBAAgB,CAAC,KAAK,EAAE,CAAC;oBAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrC,CAAC;YACL,CAAC,CAAC;YACF,IAAI,CAAC,KAAK,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC5D,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC;KAAA;IAED;;;;OAIG;IACH,6DAA6D;IACtD,QAAQ,CAAC,IAAY;QACxB,OAAO,EAAE,CAAC;IACd,CAAC;IAiBD;;;;;OAKG;IACH,6DAA6D;IACtD,YAAY,CAAC,WAAmC,EAAE,SAAiC;QACtF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Backend, WorkerDiagnostic } from "../../Backend";
|
|
2
|
+
import { SyncExtras } from "comsync";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of a JavaScript backend for Papyros
|
|
5
|
+
* by using eval and overriding some builtins
|
|
6
|
+
*/
|
|
7
|
+
export declare class JavaScriptWorker extends Backend<SyncExtras> {
|
|
8
|
+
/**
|
|
9
|
+
* Convert varargs to a string, similar to how the console does it
|
|
10
|
+
* @param {any[]} args The values to join into a string
|
|
11
|
+
* @return {string} The string representation
|
|
12
|
+
*/
|
|
13
|
+
private static stringify;
|
|
14
|
+
/**
|
|
15
|
+
* Prompt the user for input with a message
|
|
16
|
+
* @param {string} text The message to show when asking for input
|
|
17
|
+
* @return {string} The value the user gave
|
|
18
|
+
*/
|
|
19
|
+
private prompt;
|
|
20
|
+
/**
|
|
21
|
+
* Print values to the output screen
|
|
22
|
+
* @param {any[]} args The values to log
|
|
23
|
+
*/
|
|
24
|
+
private consoleLog;
|
|
25
|
+
/**
|
|
26
|
+
* Print values to the error screen
|
|
27
|
+
* @param {any[]} args The error values to log
|
|
28
|
+
*/
|
|
29
|
+
private consoleError;
|
|
30
|
+
/**
|
|
31
|
+
* Helper method to generate suggestions based on properties in an object
|
|
32
|
+
* @param {number} from Where in the document the autocompletion starts
|
|
33
|
+
* @param {any} object Object with properties that might be relevant
|
|
34
|
+
* @return {CompletionResult} Autocompletion suggestions
|
|
35
|
+
*/
|
|
36
|
+
private static completeProperties;
|
|
37
|
+
runCode(extras: SyncExtras, code: string): Promise<any>;
|
|
38
|
+
lintCode(): Promise<Array<WorkerDiagnostic>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Backend } from "../../Backend";
|
|
11
|
+
import { BackendEventType } from "../../../communication/BackendEvent";
|
|
12
|
+
/**
|
|
13
|
+
* Implementation of a JavaScript backend for Papyros
|
|
14
|
+
* by using eval and overriding some builtins
|
|
15
|
+
*/
|
|
16
|
+
export class JavaScriptWorker extends Backend {
|
|
17
|
+
/**
|
|
18
|
+
* Convert varargs to a string, similar to how the console does it
|
|
19
|
+
* @param {any[]} args The values to join into a string
|
|
20
|
+
* @return {string} The string representation
|
|
21
|
+
*/
|
|
22
|
+
static stringify(...args) {
|
|
23
|
+
const asString = args
|
|
24
|
+
.map((a) => {
|
|
25
|
+
if (Array.isArray(a)) {
|
|
26
|
+
return JSON.stringify(a);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof a === "string") {
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
else if (typeof a === "number") {
|
|
32
|
+
return a + "";
|
|
33
|
+
}
|
|
34
|
+
else if (typeof a === "object" && "toString" in a) {
|
|
35
|
+
let aString = a.toString();
|
|
36
|
+
if (aString === "[object Object]") {
|
|
37
|
+
// useless toString, so use JSON
|
|
38
|
+
aString = JSON.stringify(a);
|
|
39
|
+
}
|
|
40
|
+
return aString;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return JSON.stringify(args);
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
.join(" ");
|
|
47
|
+
return asString;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Prompt the user for input with a message
|
|
51
|
+
* @param {string} text The message to show when asking for input
|
|
52
|
+
* @return {string} The value the user gave
|
|
53
|
+
*/
|
|
54
|
+
prompt(text = "") {
|
|
55
|
+
return this.onEvent({
|
|
56
|
+
type: BackendEventType.Input,
|
|
57
|
+
data: text,
|
|
58
|
+
contentType: "text/plain",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Print values to the output screen
|
|
63
|
+
* @param {any[]} args The values to log
|
|
64
|
+
*/
|
|
65
|
+
consoleLog(...args) {
|
|
66
|
+
this.queue.put(BackendEventType.Output, JavaScriptWorker.stringify(...args) + "\n", "text/plain");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Print values to the error screen
|
|
70
|
+
* @param {any[]} args The error values to log
|
|
71
|
+
*/
|
|
72
|
+
consoleError(...args) {
|
|
73
|
+
this.queue.put(BackendEventType.Error, JavaScriptWorker.stringify(...args) + "\n", "text/plain");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Helper method to generate suggestions based on properties in an object
|
|
77
|
+
* @param {number} from Where in the document the autocompletion starts
|
|
78
|
+
* @param {any} object Object with properties that might be relevant
|
|
79
|
+
* @return {CompletionResult} Autocompletion suggestions
|
|
80
|
+
*/
|
|
81
|
+
static completeProperties(from, object) {
|
|
82
|
+
const options = Object.keys(object).map((name) => {
|
|
83
|
+
return {
|
|
84
|
+
label: name,
|
|
85
|
+
type: typeof object[name] === "function" ? "function" : "variable",
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
from,
|
|
90
|
+
options,
|
|
91
|
+
validFor: /^[\w$]*$/,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
runCode(extras, code) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
this.extras = extras;
|
|
97
|
+
this.queue.reset();
|
|
98
|
+
// Builtins to store before execution and restore afterwards
|
|
99
|
+
// Workers do not have access to prompt
|
|
100
|
+
const oldContent = {
|
|
101
|
+
"console.log": console.log,
|
|
102
|
+
"console.error": console.error,
|
|
103
|
+
};
|
|
104
|
+
// Overrides for the builtins
|
|
105
|
+
const newContext = {
|
|
106
|
+
prompt: this.prompt.bind(this),
|
|
107
|
+
"console.log": this.consoleLog.bind(this),
|
|
108
|
+
"console.error": this.consoleError.bind(this),
|
|
109
|
+
};
|
|
110
|
+
// Override the builtins
|
|
111
|
+
new Function("ctx", Object.keys(newContext)
|
|
112
|
+
.map((k) => `${k} = ctx['${k}'];`)
|
|
113
|
+
.join("\n"))(newContext);
|
|
114
|
+
let result;
|
|
115
|
+
try {
|
|
116
|
+
// run the user's code
|
|
117
|
+
this.onEvent({
|
|
118
|
+
type: BackendEventType.Start,
|
|
119
|
+
contentType: "text/plain",
|
|
120
|
+
data: "RunCode",
|
|
121
|
+
});
|
|
122
|
+
result = yield eval(code);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// try to create a friendly traceback
|
|
126
|
+
Error.captureStackTrace(error);
|
|
127
|
+
result = yield this.onEvent({
|
|
128
|
+
type: BackendEventType.Error,
|
|
129
|
+
contentType: "application/json",
|
|
130
|
+
data: {
|
|
131
|
+
name: error.constructor.name,
|
|
132
|
+
what: error.message,
|
|
133
|
+
traceback: error.stack,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
// restore the old builtins
|
|
139
|
+
new Function("ctx", Object.keys(oldContent)
|
|
140
|
+
.map((k) => `${k} = ctx['${k}'];`)
|
|
141
|
+
.join("\n"))(oldContent);
|
|
142
|
+
this.queue.flush();
|
|
143
|
+
this.onEvent({
|
|
144
|
+
type: BackendEventType.End,
|
|
145
|
+
contentType: "text/plain",
|
|
146
|
+
data: "CodeFinished",
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
lintCode() {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
return Promise.resolve([]);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=JavaScriptWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JavaScriptWorker.js","sourceRoot":"","sources":["../../../../src/backend/workers/javascript/JavaScriptWorker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAGvE;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,OAAmB;IACrD;;;;OAIG;IACK,MAAM,CAAC,SAAS,CAAC,GAAG,IAAW;QACnC,MAAM,QAAQ,GAAG,IAAI;aAChB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACP,IAAI,KAAK,CAAC,OAAO,CAAC,CA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IAEqB,QAAQ;;YAC1B,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;KAAA;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../src/backend/workers/javascript/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;AACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Backend, RunMode, WorkerDiagnostic } from "../../Backend";
|
|
2
|
+
import { BackendEvent } from "../../../communication/BackendEvent";
|
|
3
|
+
import { PyodideExtras } from "pyodide-worker-runner";
|
|
4
|
+
/**
|
|
5
|
+
* Implementation of a Python backend for Papyros
|
|
6
|
+
* Powered by Pyodide (https://pyodide.org/)
|
|
7
|
+
*/
|
|
8
|
+
export declare class PythonWorker extends Backend<PyodideExtras> {
|
|
9
|
+
private pyodide;
|
|
10
|
+
private papyros;
|
|
11
|
+
/**
|
|
12
|
+
* Promise to asynchronously install imports needed by the code
|
|
13
|
+
*/
|
|
14
|
+
private installPromise;
|
|
15
|
+
constructor();
|
|
16
|
+
private static convert;
|
|
17
|
+
/**
|
|
18
|
+
* @return {any} Function to expose a method with Pyodide support
|
|
19
|
+
*/
|
|
20
|
+
protected syncExpose(): any;
|
|
21
|
+
private static getPyodide;
|
|
22
|
+
launch(onEvent: (e: BackendEvent) => void): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Helper method to install imports and prevent race conditions with double downloading
|
|
25
|
+
* @param {string} code The code containing import statements
|
|
26
|
+
*/
|
|
27
|
+
private installImports;
|
|
28
|
+
runModes(code: string): Array<RunMode>;
|
|
29
|
+
runCode(extras: PyodideExtras, code: string, mode?: string): Promise<any>;
|
|
30
|
+
lintCode(code: string): Promise<Array<WorkerDiagnostic>>;
|
|
31
|
+
provideFiles(inlineFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Backend, RunMode } from "../../Backend";
|
|
11
|
+
import { pyodideExpose, loadPyodideAndPackage } from "pyodide-worker-runner";
|
|
12
|
+
const pythonPackageUrl = new URL("./python_package.tar.gz.load_by_url", import.meta.url).href;
|
|
13
|
+
/**
|
|
14
|
+
* Implementation of a Python backend for Papyros
|
|
15
|
+
* Powered by Pyodide (https://pyodide.org/)
|
|
16
|
+
*/
|
|
17
|
+
export class PythonWorker extends Backend {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.pyodide = {};
|
|
21
|
+
this.installPromise = null;
|
|
22
|
+
}
|
|
23
|
+
static convert(data) {
|
|
24
|
+
return data.toJs ? data.toJs({ dict_converter: Object.fromEntries }) : data;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @return {any} Function to expose a method with Pyodide support
|
|
28
|
+
*/
|
|
29
|
+
syncExpose() {
|
|
30
|
+
return pyodideExpose;
|
|
31
|
+
}
|
|
32
|
+
static getPyodide() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return yield loadPyodideAndPackage({ url: pythonPackageUrl, format: ".tgz" });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
launch(onEvent) {
|
|
38
|
+
const _super = Object.create(null, {
|
|
39
|
+
launch: { get: () => super.launch }
|
|
40
|
+
});
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield _super.launch.call(this, onEvent);
|
|
43
|
+
this.pyodide = yield PythonWorker.getPyodide();
|
|
44
|
+
// Python calls our function with a PyProxy dict or a Js Map,
|
|
45
|
+
// These must be converted to a PapyrosEvent (JS Object) to allow message passing
|
|
46
|
+
this.papyros = this.pyodide.pyimport("papyros").Papyros.callKwargs({
|
|
47
|
+
callback: (e) => {
|
|
48
|
+
const converted = PythonWorker.convert(e);
|
|
49
|
+
return this.onEvent(converted);
|
|
50
|
+
},
|
|
51
|
+
buffer_constructor: (cb) => {
|
|
52
|
+
this.queue.setCallback(cb);
|
|
53
|
+
return this.queue;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
// preload micropip to allow installing packages
|
|
57
|
+
yield this.pyodide.loadPackage("micropip");
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Helper method to install imports and prevent race conditions with double downloading
|
|
62
|
+
* @param {string} code The code containing import statements
|
|
63
|
+
*/
|
|
64
|
+
installImports(code) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a;
|
|
67
|
+
if (this.installPromise == null) {
|
|
68
|
+
this.installPromise = (_a = this.papyros) === null || _a === void 0 ? void 0 : _a.install_imports.callKwargs({
|
|
69
|
+
source_code: code,
|
|
70
|
+
ignore_missing: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
yield this.installPromise;
|
|
74
|
+
this.installPromise = null;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
runModes(code) {
|
|
78
|
+
var _a;
|
|
79
|
+
let modes = super.runModes(code);
|
|
80
|
+
if ((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.has_doctests(code)) {
|
|
81
|
+
modes = [RunMode.Doctest, ...modes];
|
|
82
|
+
}
|
|
83
|
+
modes = [RunMode.Debug, ...modes];
|
|
84
|
+
return modes;
|
|
85
|
+
}
|
|
86
|
+
runCode(extras_1, code_1) {
|
|
87
|
+
return __awaiter(this, arguments, void 0, function* (extras, code, mode = "exec") {
|
|
88
|
+
var _a;
|
|
89
|
+
this.extras = extras;
|
|
90
|
+
if (extras.interruptBuffer) {
|
|
91
|
+
this.pyodide.setInterruptBuffer(extras.interruptBuffer);
|
|
92
|
+
}
|
|
93
|
+
yield this.installImports(code);
|
|
94
|
+
return yield ((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.run_async.callKwargs({
|
|
95
|
+
source_code: code,
|
|
96
|
+
mode: mode,
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
lintCode(code) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a;
|
|
103
|
+
yield this.installImports(code);
|
|
104
|
+
return PythonWorker.convert(((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.lint(code)) || []);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
provideFiles(inlineFiles, hrefFiles) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
var _a;
|
|
110
|
+
yield ((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.provide_files.callKwargs({
|
|
111
|
+
inline_files: JSON.stringify(inlineFiles),
|
|
112
|
+
href_files: JSON.stringify(hrefFiles),
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=PythonWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PythonWorker.js","sourceRoot":"","sources":["../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AI,MAAM,CAAC,eAAe,EAAE,CAAC;gBACzB,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;YAC5D,CAAC;YACD,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAChC,OAAO,MAAM,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,CAAC,UAAU,CAAC;gBAC5C,WAAW,EAAE,IAAI;gBACjB,IAAI,EAAE,IAAI;aACb,CAAC,CAAA,CAAC;QACP,CAAC;KAAA;IAEqB,QAAQ,CAAC,IAAY;;;YACvC,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAChC,OAAO,YAAY,CAAC,OAAO,CAAC,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,CAAC,IAAI,CAAC,KAAI,EAAE,CAAC,CAAC;QAChE,CAAC;KAAA;IAEqB,YAAY,CAC9B,WAAmC,EACnC,SAAiC;;;YAEjC,MAAM,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,aAAa,CAAC,UAAU,CAAC;gBACzC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;gBACzC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;aACxC,CAAC,CAAA,CAAC;QACP,CAAC;KAAA;CACJ"}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../src/backend/workers/python/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;AAClC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing all possible types for supported events
|
|
3
|
+
*/
|
|
4
|
+
export declare enum BackendEventType {
|
|
5
|
+
Start = "start",
|
|
6
|
+
End = "end",
|
|
7
|
+
Input = "input",
|
|
8
|
+
Output = "output",
|
|
9
|
+
Sleep = "sleep",
|
|
10
|
+
Error = "error",
|
|
11
|
+
Interrupt = "interrupt",
|
|
12
|
+
Loading = "loading",
|
|
13
|
+
Frame = "frame",
|
|
14
|
+
FrameChange = "frame-change",
|
|
15
|
+
Stop = "stop"
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Interface for events used for communication between threads
|
|
19
|
+
*/
|
|
20
|
+
export interface BackendEvent {
|
|
21
|
+
/**
|
|
22
|
+
* The type of action generating this event
|
|
23
|
+
*/
|
|
24
|
+
type: BackendEventType;
|
|
25
|
+
/**
|
|
26
|
+
* The actual data stored in this event
|
|
27
|
+
*/
|
|
28
|
+
data: any;
|
|
29
|
+
/**
|
|
30
|
+
* The format used for the data to help with parsing
|
|
31
|
+
*/
|
|
32
|
+
contentType?: string;
|
|
33
|
+
}
|