From 21a0c60f5d4f8d4fcd6973f8b0f23dad294a6e13 Mon Sep 17 00:00:00 2001 From: Mohammad Al Zouabi <62098043+aboqasem@users.noreply.github.com> Date: Thu, 7 Apr 2022 17:21:48 +0800 Subject: [PATCH] make version optional --- api/src/api/v2.js | 8 +++++--- api/src/runtime.js | 4 ++-- readme.md | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/src/api/v2.js b/api/src/api/v2.js index 4f0c3e2..9ea9c04 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -69,9 +69,9 @@ function get_job(body) { message: 'language is required as a string', }); } - if (!version || typeof version !== 'string') { + if (version && typeof version !== 'string') { return reject({ - message: 'version is required as a string', + message: 'version should be a string', }); } if (!files || !Array.isArray(files)) { @@ -93,7 +93,9 @@ function get_job(body) { ); if (rt === undefined) { return reject({ - message: `${language}-${version} runtime is unknown`, + message: `${language}${ + version ? `-${version}` : '' + } runtime is unknown`, }); } diff --git a/api/src/runtime.js b/api/src/runtime.js index 6c6f10e..c0aaa70 100644 --- a/api/src/runtime.js +++ b/api/src/runtime.js @@ -194,7 +194,7 @@ module.exports.get_runtimes_matching_language_version = function (lang, ver) { return runtimes.filter( rt => (rt.language == lang || rt.aliases.includes(lang)) && - semver.satisfies(rt.version, ver) + (typeof ver !== 'string' || semver.satisfies(rt.version, ver)) ); }; module.exports.get_latest_runtime_matching_language_version = function ( @@ -211,7 +211,7 @@ module.exports.get_runtime_by_name_and_version = function (runtime, ver) { rt => (rt.runtime == runtime || (rt.runtime === undefined && rt.language == runtime)) && - semver.satisfies(rt.version, ver) + (typeof ver !== 'string' || semver.satisfies(rt.version, ver)) ); }; diff --git a/readme.md b/readme.md index 261053c..42d10db 100644 --- a/readme.md +++ b/readme.md @@ -238,8 +238,8 @@ Content-Type: application/json This endpoint requests execution of some arbitrary code. - `language` (**required**) The language to use for execution, must be a string and must be installed. -- `version` (**required**) The version of the language to use for execution, must be a string containing a SemVer selector for the version or the specific version number to use. - `files` (**required**) An array of files containing code or other data that should be used for execution. The first file in this array is considered the main file. +- `version` (_optional_) The version of the language to use for execution, must be a string containing a SemVer selector for the version or the specific version number to use. Latest version will be used if not specified. - `files[].name` (_optional_) The name of the file to upload, must be a string containing no path or left out. - `files[].content` (**required**) The content of the files to upload, must be a string containing text to write. - `files[].encoding` (_optional_) The encoding scheme used for the file content. One of `base64`, `hex` or `utf8`. Defaults to `utf8`.