Skip to content

Commit

Permalink
feat: add support for @dirigible/utils-v4 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluctuationqt authored and vmutafov committed Nov 2, 2021
1 parent 7af5d76 commit 45f57a7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
Expand Up @@ -74,7 +74,8 @@ exports.isNumeric = function(str){
var code, i, len;
for (i = 0, len = str.length; i < len; i++) {
code = str.charCodeAt(i);
if (!(code > 47 && code < 58) { // numeric (0-9)
const notNumeric = !(code > 47 && code < 58);
if (notNumeric) { // numeric (0-9)
return false;
}
}
Expand All @@ -90,9 +91,12 @@ exports.isAlphanumeric = function(str){
var code, i, len;
for (i = 0, len = str.length; i < len; i++) {
code = str.charCodeAt(i);
if (!(code > 47 && code < 58) && // numeric (0-9)
!(code > 64 && code < 91) && // upper alpha (A-Z)
!(code > 96 && code < 123)) { // lower alpha (a-z)

const notNumeric = !(code > 47 && code < 58);
const notUppercase = !(code > 64 && code < 91);
const notLowercase = !(code > 96 && code < 123);

if (notNumeric && notUppercase && notLowercase) {
return false;
}
}
Expand Down
@@ -0,0 +1,10 @@
export const alphanumeric = dirigibleRequire("utils/v4/alphanumeric");
export const assert = dirigibleRequire("utils/v4/assert");
export const base64 = dirigibleRequire("utils/v4/base64");
export const digest = dirigibleRequire("utils/v4/digest");
export const escape = dirigibleRequire("utils/v4/escape");
export const hex = dirigibleRequire("utils/v4/hex");
export const url = dirigibleRequire("utils/v4/url");
export const utf8 = dirigibleRequire("utils/v4/utf8");
export const uuid = dirigibleRequire("utils/v4/uuid");
export const xml = dirigibleRequire("utils/v4/xml");
Expand Up @@ -203,11 +203,13 @@ public Object executeService(String moduleOrCode, Map<Object, Object> executionC

var code = "";
if (moduleOrCode.endsWith(".mjs")) {
context.eval(ENGINE_JAVA_SCRIPT, Require.DIRIGIBLE_REQUIRE_CODE);
code = (isDebugEnabled ? CODE_DEBUGGER : "")
+ (isModule ? loadSource(moduleOrCode) : moduleOrCode);
context.eval(ENGINE_JAVA_SCRIPT, Require.CODE);
context.eval(ENGINE_JAVA_SCRIPT, Require.DIRIGIBLE_REQUIRE_CODE); // alias of Require.CODE
context.eval(ENGINE_JAVA_SCRIPT, isDebugEnabled ? CODE_DEBUGGER : "");
context.eval(ENGINE_JAVA_SCRIPT, "globalThis.console = require('core/v4/console');");

String fileName = isModule ? moduleOrCode : "unknown";
code = (isModule ? loadSource(moduleOrCode) : moduleOrCode);
Source src = Source.newBuilder("js", code, fileName).mimeType("application/javascript+module").build();

beforeEval(context);
Expand Down
Expand Up @@ -78,7 +78,17 @@ public Path parsePath(URI uri) {

@Override
public Path parsePath(String path) {
return handlePossibleDirigiblePath(path);
String dirigibleScope = "@dirigible";

if(path.startsWith(dirigibleScope))
{
path = path.substring(dirigibleScope.length()).replace('-', '/');
String api = StringUtils.substringBeforeLast(path, "/");
api = StringUtils.substringAfterLast(api,"/") + ".mjs";
path += "/" + api;
}

return handlePossibleDirigiblePath(Paths.get(path));
}

@Override
Expand Down

0 comments on commit 45f57a7

Please sign in to comment.