Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

troika-worker-utils

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

troika-worker-utils - npm Package Compare versions

Comparing version 0.19.0 to 0.20.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.20.0](https://github.com/protectwise/troika/compare/v0.19.0...v0.20.0) (2020-03-16)
### Features
* **troika-worker-utils:** export function for stringifying functions ([977634b](https://github.com/protectwise/troika/commit/977634b5eecb41e4e7aa61addf5b7bfd721ab9e2))
# [0.19.0](https://github.com/protectwise/troika/compare/v0.19.0-alpha.0...v0.19.0) (2020-02-28)

@@ -8,0 +19,0 @@

2

dist/troika-worker-utils.esm.js

@@ -456,2 +456,2 @@ /**

export { Thenable, ThenableWorkerModule, defineWorkerModule };
export { Thenable, ThenableWorkerModule, defineWorkerModule, stringifyFunction };

@@ -488,2 +488,3 @@ (function (global, factory) {

exports.defineWorkerModule = defineWorkerModule;
exports.stringifyFunction = stringifyFunction;

@@ -490,0 +491,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -1,9 +0,9 @@

'use strict';(function(l,p){"object"===typeof exports&&"undefined"!==typeof module?p(exports):"function"===typeof define&&define.amd?define(["exports"],p):(l=l||self,p(l.troika_worker_utils={}))})(this,function(l){function p(){function b(w,k){r++;var h=0;try{k===n&&e();var d=0<w&&q(k);d?d.call(k,c(function(a){h++;b(1,a)}),c(function(a){h++;b(-1,a)})):(m=w,a=k,g||(setTimeout(f,0),g=1))}catch(A){m||h||b(-1,A)}}function f(){var a=h;g=0;h=[];a.forEach(d)}function d(a){a()}function q(a){a=a&&(l(a)||"object"===
typeof a)&&a.then;return l(a)&&a}function c(a){var e=0;return function(){for(var b=[],k=arguments.length;k--;)b[k]=arguments[k];e++||a.apply(this,b)}}function e(){throw new TypeError("Chaining cycle detected");}var m=0,h=[],a,g=0,r=0,k=c(function(a){r||b(1,a)}),B=c(function(a){r||b(-1,a)}),l=function(a){return"function"===typeof a},n={then:function(b,k){var c=p();h.push(function(){var g=0<m?b:k;if(l(g))try{var h=g(a);h===c&&e();var d=q(h);d?d.call(h,c.resolve,c.reject):c.resolve(h)}catch(C){c.reject(C)}else c[0<
m?"resolve":"reject"](a)});m&&!g&&(setTimeout(f,0),g=1);return c},resolve:k,reject:B};return n}function D(){var b,f,d=new Promise(function(d,c){b=d;f=c});return{then:d.then.bind(d),resolve:b,reject:f}}function t(b){function f(){for(var a=[],b=arguments.length;b--;)a[b]=arguments[b];h||(h=y(e,"registerModule",f.workerModuleData));return h.then(function(b){if(b.isCallable)return y(e,"callModule",{id:m,args:a});throw Error("Worker module function was called but `init` did not return a callable function");
})}if(!b||"function"!==typeof b.init)throw Error("requires `options.init` function");var d=b.dependencies,q=b.init,c=b.getTransferables,e=b.workerId;null==e&&(e="#default");var m="workerModule"+ ++E,h=null;d=d&&d.map(function(a){"function"!==typeof a||a.workerModuleData||(a=t({workerId:e,init:(new Function("return function(){return ("+u(a)+")}"))()}));a&&a.workerModuleData&&(a=a.workerModuleData);return a});f.workerModuleData={isWorkerModule:!0,id:m,dependencies:d,init:u(q),getTransferables:c&&u(c)};
return f}function u(b){b=b.toString();!/^function/.test(b)&&/^\w+\s*\(/.test(b)&&(b="function "+b);return b}function F(b){var f=z[b];f||(f=z[b]=new Worker(URL.createObjectURL(new Blob([";("+function(){function b(e,d){var h=e.id,a=e.dependencies;void 0===a&&(a=[]);var g=e.init;void 0===g&&(g=function(){});e=e.getTransferables;void 0===e&&(e=null);if(!c[h])try{a=a.map(function(a){a&&a.isWorkerModule&&(b(a,function(a){if(a instanceof Error)throw a;}),a=c[a.id].value);return a});g=(new Function("return ("+
g+")"))();e&&(e=(new Function("return ("+e+")"))());var m=g.apply(void 0,a);c[h]={id:h,value:m,getTransferables:e};d(m)}catch(k){k&&k.noLog||console.error(k),d(k)}}function f(b,d){function e(a){try{var b=c[g].getTransferables&&c[g].getTransferables(a);b&&Array.isArray(b)&&b.length||(b=void 0);d(a,b)}catch(x){console.error(x),d(x)}}var a,g=b.id;b=b.args;c[g]&&"function"===typeof c[g].value||d(Error("Worker module "+g+": not found or its 'init' did not return a function"));try{var f=(a=c[g]).value.apply(a,
b);f&&"function"===typeof f.then?f.then(e,function(a){return d(a instanceof Error?a:Error(""+a))}):e(f)}catch(k){d(k)}}var c=Object.create(null);self.addEventListener("message",function(e){var d=e.data,c=d.messageId;e=d.action;d=d.data;try{"registerModule"===e&&b(d,function(a){a instanceof Error?postMessage({messageId:c,success:!1,error:a.message}):postMessage({messageId:c,success:!0,result:{isCallable:"function"===typeof a}})}),"callModule"===e&&f(d,function(a,b){a instanceof Error?postMessage({messageId:c,
success:!1,error:a.message}):postMessage({messageId:c,success:!0,result:a},b||void 0)})}catch(a){postMessage({messageId:c,success:!1,error:a.stack})}})}.toString()+")()"],{type:"application/javascript"}))),f.onmessage=function(b){b=b.data;var d=b.messageId,c=n[d];if(!c)throw Error("WorkerModule response with empty or unknown messageId");delete n[d];n.count--;c(b)});return f}function y(b,f,d){var l=v(),c=++G;n[c]=function(b){b.success?l.resolve(b.result):l.reject(Error("Error in worker "+f+" call: "+
b.error))};n._count++;1E3<n.count&&console.warn("Large number of open WorkerModule requests, some may not be returning");F(b).postMessage({messageId:c,action:f,data:d});return l}var v="function"===typeof Promise?D:p,E=0,G=0,z=Object.create(null),n=Object.create(null);n._count=0;var H=t({dependencies:[v],init:function(b){return b}});l.Thenable=v;l.ThenableWorkerModule=H;l.defineWorkerModule=t;Object.defineProperty(l,"__esModule",{value:!0})});
'use strict';(function(k,p){"object"===typeof exports&&"undefined"!==typeof module?p(exports):"function"===typeof define&&define.amd?define(["exports"],p):(k=k||self,p(k.troika_worker_utils={}))})(this,function(k){function p(){function b(v,l){r++;var h=0;try{l===n&&e();var d=0<v&&w(l);d?d.call(l,c(function(a){h++;b(1,a)}),c(function(a){h++;b(-1,a)})):(m=v,a=l,g||(setTimeout(f,0),g=1))}catch(A){m||h||b(-1,A)}}function f(){var a=h;g=0;h=[];a.forEach(d)}function d(a){a()}function w(a){a=a&&(k(a)||"object"===
typeof a)&&a.then;return k(a)&&a}function c(a){var e=0;return function(){for(var b=[],l=arguments.length;l--;)b[l]=arguments[l];e++||a.apply(this,b)}}function e(){throw new TypeError("Chaining cycle detected");}var m=0,h=[],a,g=0,r=0,l=c(function(a){r||b(1,a)}),B=c(function(a){r||b(-1,a)}),k=function(a){return"function"===typeof a},n={then:function(b,l){var c=p();h.push(function(){var g=0<m?b:l;if(k(g))try{var h=g(a);h===c&&e();var d=w(h);d?d.call(h,c.resolve,c.reject):c.resolve(h)}catch(C){c.reject(C)}else c[0<
m?"resolve":"reject"](a)});m&&!g&&(setTimeout(f,0),g=1);return c},resolve:l,reject:B};return n}function D(){var b,f,d=new Promise(function(d,c){b=d;f=c});return{then:d.then.bind(d),resolve:b,reject:f}}function t(b){function f(){for(var a=[],b=arguments.length;b--;)a[b]=arguments[b];h||(h=y(e,"registerModule",f.workerModuleData));return h.then(function(b){if(b.isCallable)return y(e,"callModule",{id:m,args:a});throw Error("Worker module function was called but `init` did not return a callable function");
})}if(!b||"function"!==typeof b.init)throw Error("requires `options.init` function");var d=b.dependencies,k=b.init,c=b.getTransferables,e=b.workerId;null==e&&(e="#default");var m="workerModule"+ ++E,h=null;d=d&&d.map(function(a){"function"!==typeof a||a.workerModuleData||(a=t({workerId:e,init:(new Function("return function(){return ("+q(a)+")}"))()}));a&&a.workerModuleData&&(a=a.workerModuleData);return a});f.workerModuleData={isWorkerModule:!0,id:m,dependencies:d,init:q(k),getTransferables:c&&q(c)};
return f}function q(b){b=b.toString();!/^function/.test(b)&&/^\w+\s*\(/.test(b)&&(b="function "+b);return b}function F(b){var f=z[b];f||(f=z[b]=new Worker(URL.createObjectURL(new Blob([";("+function(){function b(e,d){var h=e.id,a=e.dependencies;void 0===a&&(a=[]);var g=e.init;void 0===g&&(g=function(){});e=e.getTransferables;void 0===e&&(e=null);if(!c[h])try{a=a.map(function(a){a&&a.isWorkerModule&&(b(a,function(a){if(a instanceof Error)throw a;}),a=c[a.id].value);return a});g=(new Function("return ("+
g+")"))();e&&(e=(new Function("return ("+e+")"))());var m=g.apply(void 0,a);c[h]={id:h,value:m,getTransferables:e};d(m)}catch(l){l&&l.noLog||console.error(l),d(l)}}function f(b,d){function e(a){try{var b=c[g].getTransferables&&c[g].getTransferables(a);b&&Array.isArray(b)&&b.length||(b=void 0);d(a,b)}catch(x){console.error(x),d(x)}}var a,g=b.id;b=b.args;c[g]&&"function"===typeof c[g].value||d(Error("Worker module "+g+": not found or its 'init' did not return a function"));try{var f=(a=c[g]).value.apply(a,
b);f&&"function"===typeof f.then?f.then(e,function(a){return d(a instanceof Error?a:Error(""+a))}):e(f)}catch(l){d(l)}}var c=Object.create(null);self.addEventListener("message",function(e){var d=e.data,c=d.messageId;e=d.action;d=d.data;try{"registerModule"===e&&b(d,function(a){a instanceof Error?postMessage({messageId:c,success:!1,error:a.message}):postMessage({messageId:c,success:!0,result:{isCallable:"function"===typeof a}})}),"callModule"===e&&f(d,function(a,b){a instanceof Error?postMessage({messageId:c,
success:!1,error:a.message}):postMessage({messageId:c,success:!0,result:a},b||void 0)})}catch(a){postMessage({messageId:c,success:!1,error:a.stack})}})}.toString()+")()"],{type:"application/javascript"}))),f.onmessage=function(b){b=b.data;var d=b.messageId,c=n[d];if(!c)throw Error("WorkerModule response with empty or unknown messageId");delete n[d];n.count--;c(b)});return f}function y(b,f,d){var k=u(),c=++G;n[c]=function(b){b.success?k.resolve(b.result):k.reject(Error("Error in worker "+f+" call: "+
b.error))};n._count++;1E3<n.count&&console.warn("Large number of open WorkerModule requests, some may not be returning");F(b).postMessage({messageId:c,action:f,data:d});return k}var u="function"===typeof Promise?D:p,E=0,G=0,z=Object.create(null),n=Object.create(null);n._count=0;var H=t({dependencies:[u],init:function(b){return b}});k.Thenable=u;k.ThenableWorkerModule=H;k.defineWorkerModule=t;k.stringifyFunction=q;Object.defineProperty(k,"__esModule",{value:!0})});
{
"name": "troika-worker-utils",
"version": "0.19.0",
"version": "0.20.0",
"description": "Utilities for executing code in Web Workers",

@@ -17,3 +17,3 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>",

"module:src": "src/index.js",
"gitHead": "948b0be7399134a718e6b845682699e704631623"
"gitHead": "c97a9f97c30cd4ddfba068430d02d7c0a73c2e08"
}
// Troika worker utility exports
export {defineWorkerModule} from './WorkerModules.js'
export {defineWorkerModule, stringifyFunction} from './WorkerModules.js'
export {default as Thenable} from './Thenable.js'
export {default as ThenableWorkerModule} from './ThenableWorkerModule.js'

@@ -95,3 +95,3 @@ import Thenable from './Thenable.js'

*/
function stringifyFunction(fn) {
export function stringifyFunction(fn) {
let str = fn.toString()

@@ -98,0 +98,0 @@ // If it was defined in object method/property format, it needs to be modified

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc