@loaders.gl/worker-utils
Advanced tools
Comparing version 3.0.0-alpha.6 to 3.0.0-alpha.7
@@ -146,3 +146,3 @@ "use strict"; | ||
const VERSION = typeof "3.0.0-alpha.6" !== 'undefined' ? "3.0.0-alpha.6" : 'latest'; | ||
const VERSION = typeof "3.0.0-alpha.7" !== 'undefined' ? "3.0.0-alpha.7" : 'latest'; | ||
const NullWorker = { | ||
@@ -149,0 +149,0 @@ id: 'null', |
@@ -20,3 +20,3 @@ "use strict"; | ||
const LATEST = 'beta'; | ||
const VERSION = typeof "3.0.0-alpha.6" !== 'undefined' ? "3.0.0-alpha.6" : LATEST; | ||
const VERSION = typeof "3.0.0-alpha.7" !== 'undefined' ? "3.0.0-alpha.7" : LATEST; | ||
const loadLibraryPromises = {}; | ||
@@ -23,0 +23,0 @@ |
@@ -0,1 +1,3 @@ | ||
type ProcessFunction = (data: any, options: {[key: string]: any}) => Promise<any>; | ||
/** | ||
@@ -5,4 +7,4 @@ * Set up a WebWorkerGlobalScope to talk with the main thread | ||
export function createWorker( | ||
process: Function, | ||
process: ProcessFunction, | ||
processInBatches?: Function, | ||
): void; |
@@ -9,5 +9,4 @@ import {WorkerObject} from '../../types'; | ||
worker: WorkerObject, | ||
jobName: string, | ||
data: any, | ||
options?: object | ||
): Promise<any>; |
@@ -14,3 +14,3 @@ "use strict"; | ||
async function processOnWorker(worker, jobName, data, options = {}) { | ||
async function processOnWorker(worker, data, options = {}) { | ||
const name = (0, _workerObjectUtils.getWorkerObjectName)(worker, options); | ||
@@ -25,3 +25,3 @@ const url = (0, _workerObjectUtils.getWorkerObjectURL)(worker, options); | ||
}); | ||
const job = await workerPool.startJob(jobName, (job_, type, payload) => { | ||
const job = await workerPool.startJob(worker.name, (job_, type, payload) => { | ||
switch (type) { | ||
@@ -41,3 +41,3 @@ case 'done': | ||
}); | ||
const transferableOptions = removeNontransferableOptions(options); | ||
const transferableOptions = (0, _workerObjectUtils.removeNontransferableOptions)(options); | ||
job.postMessage('process', { | ||
@@ -50,6 +50,2 @@ input: data, | ||
} | ||
function removeNontransferableOptions(options) { | ||
return JSON.parse(JSON.stringify(options)); | ||
} | ||
//# sourceMappingURL=process-on-worker.js.map |
@@ -26,1 +26,7 @@ import {WorkerObject} from '../../types'; | ||
export function validateWorkerVersion(worker: WorkerObject, libVersion?: string): boolean; | ||
/** | ||
* Safely stringify JSON (drop non serializable values like functions and regexps) | ||
* @param value | ||
*/ | ||
export function removeNontransferableOptions(object: object): object; |
@@ -11,6 +11,8 @@ "use strict"; | ||
exports.validateWorkerVersion = validateWorkerVersion; | ||
exports.removeNontransferableOptions = removeNontransferableOptions; | ||
var _assert = _interopRequireDefault(require("../env-utils/assert")); | ||
const VERSION = typeof "3.0.0-alpha.6" !== 'undefined' ? "3.0.0-alpha.6" : 'latest'; | ||
const NPM_TAG = 'beta'; | ||
const VERSION = typeof "3.0.0-alpha.7" !== 'undefined' ? "3.0.0-alpha.7" : NPM_TAG; | ||
@@ -28,4 +30,10 @@ function getWorkerObjectURL(worker, options) { | ||
if (!url) { | ||
const version = worker.version ? "@".concat(worker.version) : ''; | ||
url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(version, "/dist/").concat(workerFile); | ||
let version = worker.version; | ||
if (version === 'latest') { | ||
version = NPM_TAG; | ||
} | ||
const versionTag = version ? "@".concat(version) : ''; | ||
url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(versionTag, "/dist/").concat(workerFile); | ||
} | ||
@@ -61,2 +69,25 @@ | ||
} | ||
function removeNontransferableOptions(object) { | ||
return JSON.parse(stringifyJSON(object)); | ||
} | ||
function stringifyJSON(v) { | ||
const cache = new Set(); | ||
return JSON.stringify(v, (key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.has(value)) { | ||
try { | ||
return JSON.parse(JSON.stringify(value)); | ||
} catch (err) { | ||
return undefined; | ||
} | ||
} | ||
cache.add(value); | ||
} | ||
return value; | ||
}); | ||
} | ||
//# sourceMappingURL=worker-object-utils.js.map |
@@ -12,3 +12,3 @@ export { default as assert } from './lib/env-utils/assert'; | ||
export { default as AsyncQueue } from './lib/async-queue/async-queue'; | ||
const VERSION = typeof "3.0.0-alpha.6" !== 'undefined' ? "3.0.0-alpha.6" : 'latest'; | ||
const VERSION = typeof "3.0.0-alpha.7" !== 'undefined' ? "3.0.0-alpha.7" : 'latest'; | ||
export const NullWorker = { | ||
@@ -15,0 +15,0 @@ id: 'null', |
@@ -5,3 +5,3 @@ import { global, isBrowser, isWorker } from '../env-utils/globals'; | ||
const LATEST = 'beta'; | ||
const VERSION = typeof "3.0.0-alpha.6" !== 'undefined' ? "3.0.0-alpha.6" : LATEST; | ||
const VERSION = typeof "3.0.0-alpha.7" !== 'undefined' ? "3.0.0-alpha.7" : LATEST; | ||
const loadLibraryPromises = {}; | ||
@@ -8,0 +8,0 @@ export async function loadLibrary(libraryUrl, moduleName = null, options = {}) { |
@@ -0,1 +1,3 @@ | ||
type ProcessFunction = (data: any, options: {[key: string]: any}) => Promise<any>; | ||
/** | ||
@@ -5,4 +7,4 @@ * Set up a WebWorkerGlobalScope to talk with the main thread | ||
export function createWorker( | ||
process: Function, | ||
process: ProcessFunction, | ||
processInBatches?: Function, | ||
): void; |
@@ -9,5 +9,4 @@ import {WorkerObject} from '../../types'; | ||
worker: WorkerObject, | ||
jobName: string, | ||
data: any, | ||
options?: object | ||
): Promise<any>; |
import WorkerFarm from '../worker-farm/worker-farm'; | ||
import { getWorkerObjectURL, getWorkerObjectName } from './worker-object-utils'; | ||
export async function processOnWorker(worker, jobName, data, options = {}) { | ||
import { getWorkerObjectURL, getWorkerObjectName, removeNontransferableOptions } from './worker-object-utils'; | ||
export async function processOnWorker(worker, data, options = {}) { | ||
const name = getWorkerObjectName(worker, options); | ||
@@ -11,3 +11,3 @@ const url = getWorkerObjectURL(worker, options); | ||
}); | ||
const job = await workerPool.startJob(jobName, (job_, type, payload) => { | ||
const job = await workerPool.startJob(worker.name, (job_, type, payload) => { | ||
switch (type) { | ||
@@ -35,6 +35,2 @@ case 'done': | ||
} | ||
function removeNontransferableOptions(options) { | ||
return JSON.parse(JSON.stringify(options)); | ||
} | ||
//# sourceMappingURL=process-on-worker.js.map |
@@ -26,1 +26,7 @@ import {WorkerObject} from '../../types'; | ||
export function validateWorkerVersion(worker: WorkerObject, libVersion?: string): boolean; | ||
/** | ||
* Safely stringify JSON (drop non serializable values like functions and regexps) | ||
* @param value | ||
*/ | ||
export function removeNontransferableOptions(object: object): object; |
import assert from '../env-utils/assert'; | ||
const VERSION = typeof "3.0.0-alpha.6" !== 'undefined' ? "3.0.0-alpha.6" : 'latest'; | ||
const NPM_TAG = 'beta'; | ||
const VERSION = typeof "3.0.0-alpha.7" !== 'undefined' ? "3.0.0-alpha.7" : NPM_TAG; | ||
export function getWorkerObjectURL(worker, options) { | ||
@@ -14,4 +15,10 @@ const topOptions = options || {}; | ||
if (!url) { | ||
const version = worker.version ? "@".concat(worker.version) : ''; | ||
url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(version, "/dist/").concat(workerFile); | ||
let version = worker.version; | ||
if (version === 'latest') { | ||
version = NPM_TAG; | ||
} | ||
const versionTag = version ? "@".concat(version) : ''; | ||
url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(versionTag, "/dist/").concat(workerFile); | ||
} | ||
@@ -45,2 +52,25 @@ | ||
} | ||
export function removeNontransferableOptions(object) { | ||
return JSON.parse(stringifyJSON(object)); | ||
} | ||
function stringifyJSON(v) { | ||
const cache = new Set(); | ||
return JSON.stringify(v, (key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.has(value)) { | ||
try { | ||
return JSON.parse(JSON.stringify(value)); | ||
} catch (err) { | ||
return undefined; | ||
} | ||
} | ||
cache.add(value); | ||
} | ||
return value; | ||
}); | ||
} | ||
//# sourceMappingURL=worker-object-utils.js.map |
{ | ||
"name": "@loaders.gl/worker-utils", | ||
"version": "3.0.0-alpha.6", | ||
"version": "3.0.0-alpha.7", | ||
"description": "Utilities for running tasks on worker threads", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "2b20a738eff9758c202b8ef787f0ca27baf3ebe1" | ||
"gitHead": "42832866753e5b62ff1a07112e6f6466f26365b0" | ||
} |
@@ -0,1 +1,3 @@ | ||
type ProcessFunction = (data: any, options: {[key: string]: any}) => Promise<any>; | ||
/** | ||
@@ -5,4 +7,4 @@ * Set up a WebWorkerGlobalScope to talk with the main thread | ||
export function createWorker( | ||
process: Function, | ||
process: ProcessFunction, | ||
processInBatches?: Function, | ||
): void; |
@@ -9,5 +9,4 @@ import {WorkerObject} from '../../types'; | ||
worker: WorkerObject, | ||
jobName: string, | ||
data: any, | ||
options?: object | ||
): Promise<any>; |
@@ -5,3 +5,7 @@ /** @typedef {import('./process-on-worker')} types */ | ||
import WorkerFarm from '../worker-farm/worker-farm'; | ||
import {getWorkerObjectURL, getWorkerObjectName} from './worker-object-utils'; | ||
import { | ||
getWorkerObjectURL, | ||
getWorkerObjectName, | ||
removeNontransferableOptions | ||
} from './worker-object-utils'; | ||
@@ -13,3 +17,3 @@ /** | ||
*/ | ||
export async function processOnWorker(worker, jobName, data, options = {}) { | ||
export async function processOnWorker(worker, data, options = {}) { | ||
const name = getWorkerObjectName(worker, options); | ||
@@ -22,3 +26,3 @@ const url = getWorkerObjectURL(worker, options); | ||
const job = await workerPool.startJob( | ||
jobName, | ||
worker.name, | ||
/** | ||
@@ -51,12 +55,1 @@ * Job completes when we receive the result | ||
} | ||
/** | ||
* @param {object} options | ||
* @returns {object} | ||
*/ | ||
function removeNontransferableOptions(options) { | ||
// options.log object contains functions which cannot be transferred | ||
// TODO - decide how to handle logging on workers | ||
// TODO - warn if options stringification is long | ||
return JSON.parse(JSON.stringify(options)); | ||
} |
@@ -26,1 +26,7 @@ import {WorkerObject} from '../../types'; | ||
export function validateWorkerVersion(worker: WorkerObject, libVersion?: string): boolean; | ||
/** | ||
* Safely stringify JSON (drop non serializable values like functions and regexps) | ||
* @param value | ||
*/ | ||
export function removeNontransferableOptions(object: object): object; |
/** @typedef {import('../../types').WorkerObject} WorkerObject */ | ||
import assert from '../env-utils/assert'; | ||
const NPM_TAG = 'beta'; // Change to 'latest' on release-branch | ||
// __VERSION__ is injected by babel-plugin-version-inline | ||
// @ts-ignore TS2304: Cannot find name '__VERSION__'. | ||
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest'; | ||
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : NPM_TAG; | ||
@@ -21,7 +23,12 @@ export function getWorkerObjectURL(worker, options) { | ||
// If url not provided, load from CDN | ||
// If url override is not provided, generate a URL to published version on npm CDN unpkg.com | ||
if (!url) { | ||
// GENERATE | ||
const version = worker.version ? `@${worker.version}` : ''; | ||
url = `https://unpkg.com/@loaders.gl/${worker.module}${version}/dist/${workerFile}`; | ||
let version = worker.version; | ||
// On master we need to load npm alpha releases published with the `beta` tag | ||
if (version === 'latest') { | ||
version = NPM_TAG; | ||
} | ||
const versionTag = version ? `@${version}` : ''; | ||
url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`; | ||
} | ||
@@ -66,1 +73,33 @@ | ||
} | ||
/** | ||
* @param {object} object | ||
* @returns {object} | ||
*/ | ||
export function removeNontransferableOptions(object) { | ||
// options.log object contains functions which cannot be transferred | ||
// TODO - decide how to handle logging on workers | ||
// TODO - warn if options stringification is long | ||
return JSON.parse(stringifyJSON(object)); | ||
} | ||
function stringifyJSON(v) { | ||
const cache = new Set(); | ||
return JSON.stringify(v, (key, value) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.has(value)) { | ||
// Circular reference found | ||
try { | ||
// If this value does not reference a parent it can be deduped | ||
return JSON.parse(JSON.stringify(value)); | ||
} catch (err) { | ||
// discard key if value cannot be deduped | ||
return undefined; | ||
} | ||
} | ||
// Store value in our set | ||
cache.add(value); | ||
} | ||
return value; | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
309418
4707
18