UNPKG

@dodona/papyros

Version:

Scratchpad for multiple programming languages in the browser.

114 lines (113 loc) 4.27 kB
import { BackendEvent } from "../communication/BackendEvent"; import { SyncExtras } from "comsync"; import { BackendEventQueue } from "../communication/BackendEventQueue"; export interface WorkerDiagnostic { /** * 1-based index of the starting line containing the issue */ lineNr: number; /** * 0-based index of the column in the starting line */ columnNr: number; /** * 1-based index of the ending line containing the issue * Can be the same as lineNr */ endLineNr: number; /** * 0-based index of the column in the ending line */ endColumnNr: number; /** * Severity of the issue */ severity: "info" | "warning" | "error"; /** * Message describing the issue */ message: string; } export declare enum RunMode { Run = "run", Debug = "debug", Doctest = "doctest" } export declare abstract class Backend<Extras extends SyncExtras = SyncExtras> { /** * SyncExtras object that grants access to helpful methods * for synchronous operations */ protected extras: Extras; /** * Callback to handle events published by this Backend */ protected onEvent: (e: BackendEvent) => any; /** * Queue to handle published events without overloading the thread */ protected queue: BackendEventQueue; /** * 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(); /** * @return {any} The function to expose methods for Comsync to allow interrupting */ protected syncExpose(): any; /** * 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: (e: BackendEvent) => void): Promise<void>; /** * 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 */ runModes(code: string): Array<RunMode>; /** * Executes the given code * @param {Extras} extras Helper properties to run code * @param {string} code The code to run * @param {string} mode The mode to run the code in * @return {Promise<void>} Promise of execution */ abstract runCode(extras: Extras, code: string, mode?: string): Promise<void>; /** * Generate linting suggestions for the given code * @param {string} code The code to lint */ abstract lintCode(code: string): Promise<Array<WorkerDiagnostic>>; /** * 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 */ provideFiles(inlineFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void>; /** * 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 */ deleteFile(name: string): Promise<void>; /** * 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 */ updateFile(name: string, content: string, binary: boolean): Promise<void>; /** * 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 */ renameFile(oldName: string, newName: string): Promise<void>; }