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.34.0 to 0.34.1

0

__tests__/_jsdom-worker.js

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ const promisesAplusTests = require('promises-aplus-tests')

@@ -0,0 +0,0 @@ require('./_jsdom-worker.js')

@@ -0,0 +0,0 @@ require('./_jsdom-worker.js')

12

CHANGELOG.md

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

## [0.34.1](https://github.com/protectwise/troika/compare/v0.34.0...v0.34.1) (2020-10-20)
### Bug Fixes
* check for process env 'test' ([4f7f8f2](https://github.com/protectwise/troika/commit/4f7f8f24a9d4f4b655b61e1e16e19061c1911b02))
* check if process is undefined ([2b6d56a](https://github.com/protectwise/troika/commit/2b6d56af78e175a74fb03442efdc0a10d18fa4c8))
# [0.34.0](https://github.com/protectwise/troika/compare/v0.33.1...v0.34.0) (2020-10-19)

@@ -8,0 +20,0 @@

10

dist/troika-worker-utils.esm.js

@@ -409,5 +409,3 @@ /**

var worker = new Worker(
URL.createObjectURL(
new Blob([''], { type: 'application/javascript' })
)
URL.createObjectURL(new Blob([''], { type: 'application/javascript' }))
);

@@ -417,3 +415,7 @@ worker.terminate();

} catch (err) {
console.log(("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + (err.message) + "]"));
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') ; else {
console.log(
("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + (err.message) + "]")
);
}
}

@@ -420,0 +422,0 @@ }

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.troika_worker_utils = {}));
(global = global || self, factory(global.troika_worker_utils = {}));
}(this, (function (exports) { 'use strict';

@@ -415,5 +415,3 @@

var worker = new Worker(
URL.createObjectURL(
new Blob([''], { type: 'application/javascript' })
)
URL.createObjectURL(new Blob([''], { type: 'application/javascript' }))
);

@@ -423,3 +421,7 @@ worker.terminate();

} catch (err) {
console.log(("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + (err.message) + "]"));
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') ; else {
console.log(
("Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + (err.message) + "]")
);
}
}

@@ -426,0 +428,0 @@ }

@@ -1,13 +0,13 @@

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

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

"module:src": "src/index.js",
"gitHead": "b19cd3aff4b0876253d76b3fc66b7e2a1f16a7e5"
"gitHead": "04c819dd9013c686b872cd16bcaaf4de8723723e"
}

@@ -0,0 +0,0 @@ # `troika-worker-utils`

@@ -0,0 +0,0 @@ // Troika worker utility exports

@@ -0,0 +0,0 @@ import Thenable from './Thenable.js'

@@ -11,5 +11,3 @@ let supportsWorkers = () => {

let worker = new Worker(
URL.createObjectURL(
new Blob([''], { type: 'application/javascript' })
)
URL.createObjectURL(new Blob([''], { type: 'application/javascript' }))
)

@@ -19,3 +17,9 @@ worker.terminate()

} catch (err) {
console.log(`Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [${err.message}]`)
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
// No console log for node env 'test' (e.g. tests with Jest)
} else {
console.log(
`Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [${err.message}]`
)
}
}

@@ -22,0 +26,0 @@ }

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ import Thenable from './Thenable.js'

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ import Thenable from './Thenable.js'

Sorry, the diff of this file is not supported yet

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