UNPKG

@dodona/papyros

Version:

Scratchpad for multiple programming languages in the browser.

109 lines 4.53 kB
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()); }); }; import { BackendEventType } from "../communication/BackendEvent"; import { syncExpose } from "comsync"; import { BackendEventQueue } from "../communication/BackendEventQueue"; export var RunMode; (function (RunMode) { RunMode["Run"] = "run"; RunMode["Debug"] = "debug"; RunMode["Doctest"] = "doctest"; })(RunMode || (RunMode = {})); export class Backend { /** * Constructor is limited as it is meant to be used as a WebWorker * Proper initialization occurs in the launch method when the worker is started * Synchronously exposing methods should be done here */ constructor() { this.extras = {}; this.onEvent = () => { // Empty, initialized in launch }; this.runCode = this.syncExpose()(this.runCode.bind(this)); this.queue = {}; } /** * @return {any} The function to expose methods for Comsync to allow interrupting */ syncExpose() { return syncExpose; } /** * Initialize the backend by doing all setup-related work * @param {function(BackendEvent):void} onEvent Callback for when events occur * @return {Promise<void>} Promise of launching */ launch(onEvent) { return __awaiter(this, void 0, void 0, function* () { this.onEvent = (e) => { onEvent(e); if (e.type === BackendEventType.Sleep) { return this.extras.syncSleep(e.data); } else if (e.type === BackendEventType.Input) { return this.extras.readMessage(); } }; this.queue = new BackendEventQueue(this.onEvent.bind(this)); return Promise.resolve(); }); } /** * Determine whether the modes supported by this Backend are active * @param {string} code The current code in the editor * @return {Array<RunMode>} The run modes of this Backend */ // eslint-disable-next-line @typescript-eslint/no-unused-vars runModes(code) { return []; } /** * Provide files to be used by the backend * @param {Record<string, string>} inlineFiles Map of file names to their contents * @param {Record<string, string>} hrefFiles Map of file names to URLS with their contents * @return {Promise<void>} Resolves when the files are present in the backend */ // eslint-disable-next-line @typescript-eslint/no-unused-vars provideFiles(inlineFiles, hrefFiles) { return Promise.resolve(); } /** * Delete a file from the backend filesystem * @param {string} name The name of the file to delete * @return {Promise<void>} Resolves when the file has been deleted */ // eslint-disable-next-line @typescript-eslint/no-unused-vars deleteFile(name) { return Promise.resolve(); } /** * Update the content of a file in the backend filesystem * @param {string} name The name of the file to update * @param {string} content The new content of the file; base64-encoded when binary is true * @param {boolean} binary Whether the content is binary (base64-encoded) rather than plain text * @return {Promise<void>} Resolves when the file has been updated */ // eslint-disable-next-line @typescript-eslint/no-unused-vars updateFile(name, content, binary) { return Promise.resolve(); } /** * Rename a file in the backend filesystem * @param {string} oldName The current name of the file * @param {string} newName The new name of the file * @return {Promise<void>} Resolves when the file has been renamed */ // eslint-disable-next-line @typescript-eslint/no-unused-vars renameFile(oldName, newName) { return Promise.resolve(); } } //# sourceMappingURL=Backend.js.map