0.0.6 • Published 3 years ago

piston-js v0.0.6

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

PR's Welcome

A JavaScript client for Piston-Batch, A fork from Piston, a high performance general purpose code execution engine that supports batch submissions and code evaluation.

Contains Full TypeScript Typings

 

Installation

$ npm install piston-js

Basic Usage

import Piston from 'piston-js';

(async () => {
  const piston = new Piston('https://pistonserver.com');
  try {
    const result: SubmissionResult = await piston.run({
      language: {
        name: 'python',
        version: '3.9.1',
      },
      fileName: 'main.py',
      sourceCode: 'print(int(input())*3)',
      input: ['2'],
      expectedOutput: ['4'],
    });
    console.log(result);
    /*{
     run: [ { stdout: '6', stderr: '', code: 0, signal: null, stdin: '2' } ],
     verdict: { status: 'WA', stdout: '6', stdin: '2', expected_output: '4' }
    } */
  } catch (err) {
    console.log(err.response.data);
  }
})();

API

Piston(config: PistonConfig) : Piston

Returns an instance of Piston

PistonConfig

An object type representing the config for the Piston instance

properties

PropertyTypeDescriptionDefault
baseURLstringthe base url of the piston server-
apiKeystring?the api key used to access the piston server""
apiKeyHeaderstring?name of the api key header""

Piston.run(submission: Submission) : Promise< SubmissionResult>

Runs a submission and returns the result

Submission

An object representing a submission

properties

PropertyTypeDescriptionDefault
sourceCodestringthe source code to execute-
languageLanguagethe programming language to execute-
fileNamestringname of the file to execute, 'e.g: Main.java'. Some languages like Java need files to have the same name as the Main class.-
input?string[]batch stdin to execute""
expectedOutput?string[]if provided, the execution will be evaluated against all stdout resulted from input. if provided, must have equal length to inputnull
runTimeout?numbermilliseconds before timing out the program (TLE)3000
compileTimeout?numbermilliseconds before timing out the compilation of the source code (applies only to compiled languages) (TLE)10000

Language

Type of Language required in Submission

properties

PropertyTypeDescriptionDefault
namestringname of the language-
versionstringversion of the language-

SubmissionResult

An object representing the result of a Submission

properties

PropertyTypeDescription
compile?ProcessOutputonly available in compiled languages-
runProcessOutputresult of each individual stdin in the batch
resultBatchResultFinal result of the submission batch after evaluation

ProcessOutput

Type of an execution process output

properties

PropertyTypeDescription
stdinstringprocess stdin
stdoutstringprocess stdout
stderrstringprocess stderr
codenumberprocess return code
signalstringprocess signal

BatchResult

Type of an execution process output

properties

PropertyTypeDescription
statusVerdictsubmission evaluation verdict
stdoutstringstdout of the first failed submission in the batch
stdinstringstdin of the first failed submission in the batch
expectedOutputstringexpected output of the first failed submission in the batch
signalstringprocess signal
  • A submission is considered a failed submission in the batch if its Verdict is not accepted (AC)
  • If a submission batch is accepted, stdout and stdin will have the results of the first submission in the batch

Verdict

An enum representing the verdict of a submission as strings

PropertyValuedescription
AC'AC'The source code executed successfully/passed all test cases-
COMPILATION'COMPILATION'Compilation error-
ERROR'ERROR'An error during the whole execution process
MLE'MLE'Memory limit exceeded (NOT YET IMPLEMENTED)
PENDING'PENDING'Submission is pending
RUNTIME'RUNTIME'Runtime error
TLE'TLE'Time limit exceeded (timedout)
WA'WA'Wrong answer (Failed test cases)
0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago