Comparing version 0.1.1 to 0.1.2
@@ -17,3 +17,3 @@ "use strict"; | ||
} | ||
return new Promise(resolve => { | ||
return new Promise((resolve, reject) => { | ||
const id = Math.random(); | ||
@@ -27,3 +27,5 @@ const listener = async function listener(evt) { | ||
} = evt; | ||
if (typeof data !== "object" || data === null) return; | ||
if (typeof data !== "object" || data === null) { | ||
return; | ||
} | ||
@@ -35,3 +37,3 @@ // batch request | ||
// const times = [] | ||
let results = await Promise.all(data.map(async req => { | ||
const results = await Promise.all(data.map(async req => { | ||
// if (!req.method) throw new Error("[Microlink.call] missing method"); | ||
@@ -49,13 +51,20 @@ // if (!(req.method in params_functions)) throw new Error("[Microlink.call] invalid method"); | ||
} | ||
if (data.jsonrpc !== "2.0") return; | ||
if (data.jsonrpc !== "2.0") { | ||
return; | ||
} | ||
if (data.method && params_functions && data.method in params_functions) { | ||
if (!Array.isArray(data.params)) throw Error("[microlink.call] params should be an array"); | ||
const result = await params_functions[data.method](...data.params); | ||
const msg = { | ||
jsonrpc: "2.0", | ||
result, | ||
id: data.id | ||
}; | ||
if (debug_level >= 2) console.log("[microlink.call] posting message down to worker:", msg); | ||
return it.postMessage(msg); | ||
try { | ||
if (!Array.isArray(data.params)) throw Error("[microlink.call] params should be an array"); | ||
const result = await params_functions[data.method](...data.params); | ||
const msg = { | ||
jsonrpc: "2.0", | ||
result, | ||
id: data.id | ||
}; | ||
if (debug_level >= 2) console.log("[microlink.call] posting message down to worker:", msg); | ||
return it.postMessage(msg); | ||
} catch (error) { | ||
console.error("[microlink.call] error:", error); | ||
reject(error); | ||
} | ||
} | ||
@@ -62,0 +71,0 @@ if (data.id === id) { |
@@ -59,3 +59,3 @@ "use strict"; | ||
} catch (error) { | ||
if (debug_level >= 2) console.error("[microlink.expose] error:", error); | ||
console.error("[microlink.expose] error:", error); | ||
return postMessage({ | ||
@@ -62,0 +62,0 @@ jsonrpc: "2.0", |
@@ -148,3 +148,3 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
} | ||
return new Promise(resolve => { | ||
return new Promise((resolve, reject) => { | ||
const id = Math.random(); | ||
@@ -158,3 +158,5 @@ const listener = async function listener(evt) { | ||
} = evt; | ||
if (typeof data !== "object" || data === null) return; | ||
if (typeof data !== "object" || data === null) { | ||
return; | ||
} | ||
@@ -166,3 +168,3 @@ // batch request | ||
// const times = [] | ||
let results = await Promise.all(data.map(async req => { | ||
const results = await Promise.all(data.map(async req => { | ||
// if (!req.method) throw new Error("[Microlink.call] missing method"); | ||
@@ -180,13 +182,20 @@ // if (!(req.method in params_functions)) throw new Error("[Microlink.call] invalid method"); | ||
} | ||
if (data.jsonrpc !== "2.0") return; | ||
if (data.jsonrpc !== "2.0") { | ||
return; | ||
} | ||
if (data.method && params_functions && data.method in params_functions) { | ||
if (!Array.isArray(data.params)) throw Error("[microlink.call] params should be an array"); | ||
const result = await params_functions[data.method](...data.params); | ||
const msg = { | ||
jsonrpc: "2.0", | ||
result, | ||
id: data.id | ||
}; | ||
if (debug_level >= 2) console.log("[microlink.call] posting message down to worker:", msg); | ||
return it.postMessage(msg); | ||
try { | ||
if (!Array.isArray(data.params)) throw Error("[microlink.call] params should be an array"); | ||
const result = await params_functions[data.method](...data.params); | ||
const msg = { | ||
jsonrpc: "2.0", | ||
result, | ||
id: data.id | ||
}; | ||
if (debug_level >= 2) console.log("[microlink.call] posting message down to worker:", msg); | ||
return it.postMessage(msg); | ||
} catch (error) { | ||
console.error("[microlink.call] error:", error); | ||
reject(error); | ||
} | ||
} | ||
@@ -336,3 +345,3 @@ if (data.id === id) { | ||
} catch (error) { | ||
if (debug_level >= 2) console.error("[microlink.expose] error:", error); | ||
console.error("[microlink.expose] error:", error); | ||
return postMessage({ | ||
@@ -339,0 +348,0 @@ jsonrpc: "2.0", |
@@ -11,3 +11,3 @@ import serialize from "./serialize.js"; | ||
return new Promise(resolve => { | ||
return new Promise((resolve, reject) => { | ||
const id = Math.random(); | ||
@@ -20,3 +20,5 @@ const listener = async function listener(evt) { | ||
if (typeof data !== "object" || data === null) return; | ||
if (typeof data !== "object" || data === null) { | ||
return; | ||
} | ||
@@ -28,3 +30,3 @@ // batch request | ||
// const times = [] | ||
let results = await Promise.all( | ||
const results = await Promise.all( | ||
data.map(async req => { | ||
@@ -41,10 +43,17 @@ // if (!req.method) throw new Error("[Microlink.call] missing method"); | ||
if (data.jsonrpc !== "2.0") return; | ||
if (data.jsonrpc !== "2.0") { | ||
return; | ||
} | ||
if (data.method && params_functions && data.method in params_functions) { | ||
if (!Array.isArray(data.params)) throw Error("[microlink.call] params should be an array"); | ||
const result = await params_functions[data.method](...data.params); | ||
const msg = { jsonrpc: "2.0", result, id: data.id }; | ||
if (debug_level >= 2) console.log("[microlink.call] posting message down to worker:", msg); | ||
return it.postMessage(msg); | ||
try { | ||
if (!Array.isArray(data.params)) throw Error("[microlink.call] params should be an array"); | ||
const result = await params_functions[data.method](...data.params); | ||
const msg = { jsonrpc: "2.0", result, id: data.id }; | ||
if (debug_level >= 2) console.log("[microlink.call] posting message down to worker:", msg); | ||
return it.postMessage(msg); | ||
} catch (error) { | ||
console.error("[microlink.call] error:", error); | ||
reject(error); | ||
} | ||
} | ||
@@ -51,0 +60,0 @@ |
@@ -53,3 +53,3 @@ import deserialize from "./deserialize.js"; | ||
} catch (error) { | ||
if (debug_level >= 2) console.error("[microlink.expose] error:", error); | ||
console.error("[microlink.expose] error:", error); | ||
return postMessage({ | ||
@@ -56,0 +56,0 @@ jsonrpc: "2.0", |
{ | ||
"name": "microlink", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Comlink Alternative. Built with JSON-RPC.", | ||
@@ -29,3 +29,3 @@ "unpkg": "./dist/microlink.bundle.js", | ||
"build:bundle": "mkdir -p ./dist && npx browserify ./cjs/index.js > ./dist/microlink.bundle.js", | ||
"build:cjs": "babel --plugins @babel/plugin-transform-modules-commonjs --plugins @babel/plugin-proposal-export-namespace-from ./esm/* --out-dir ./cjs", | ||
"build:cjs": "babel --plugins @babel/plugin-transform-modules-commonjs --plugins @babel/plugin-transform-export-namespace-from ./esm/* --out-dir ./cjs", | ||
"clean": "rm -rf ./cjs/* ./dist/*", | ||
@@ -58,6 +58,6 @@ "format": "npx prettier@latest --arrow-parens=avoid --print-width=200 --trailing-comma=none --write esm test", | ||
"devDependencies": { | ||
"@babel/cli": "^7.22.9", | ||
"@babel/core": "^7.22.9", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.18.9", | ||
"@babel/plugin-transform-modules-commonjs": "^7.22.5", | ||
"@babel/cli": "^7.23.4", | ||
"@babel/core": "^7.23.5", | ||
"@babel/plugin-transform-export-namespace-from": "^7.23.4", | ||
"@babel/plugin-transform-modules-commonjs": "^7.23.3", | ||
"flug": "^2.6.0", | ||
@@ -64,0 +64,0 @@ "mock-worker": "^0.0.1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50024
1182